1

I received data from different server to my Hub class. Each data has its own ID. Whenever data comes to the server hub, it push my data to the client. This is like job progress. I want to send each ID to the client with unique hub id., How do I filter the message from the server? I used in this way Clients.Client("ID1").send(data); Or I have to specify in caller property? Anyone can help me.

With Regards, Shanthini

4

1 回答 1

3

You can use ConnectionId to identify the client.

When new client is connected, store ConnectionId somewhere so that you can use it later to identify the client.

public class MyHub : Hub
{
    public override Task OnConnected()
    {
        var connectionId = Context.ConnectionId;
        // store connectionId somewhere
        return base.OnConnected();
    }
}

To send data to the client, identify it by ConnectionId:

public void SendNewData(string connectionId, object data)
{
    var Context = GlobalHost.ConnectionManager.GetHubContext<MyHub>();
    Context.Clients.Client(connectionId).send(data);
}

If you need to identify clients by some other ID, then you should store relationship between your ID and ConnectionId.

于 2013-05-23T15:29:00.437 回答