Saturday 15 March 2014

c# - Broadcasting message to all clients except self in SignalR -


I know these questions are the same:

However, they are outdated and there is nothing in the current documents that I am right or not.

Here is the question / problem:

To broadcast a message to the server I need to broadcast all the connected clients in addition to that person, which submitted the http request - One form and all the people connected in the same form are being informed that something has been presented.

The way I am doing it is now something like this:

  var context = GlobalHost.ConnectionManager.GetHubContext & lt; MyHub & gt; (); Var connectionID = HttpContext.Request.Cookies ["conn-id"]. Values; Context.Clients.AllExcept (connectionID) .addMessage (message);   

And each time a connection is established, I am setting the connectionindex on the customer ID in a cookie:

  $ Connection.hub.start () .done (function () {$ .cookie ("conn-id", $ .connection.hub.id);});   

So my questions are:

  1. Can I take the best / only approach in this matter? Can I read the connection ID of the client which generates a request from another location such as hub.Context.ConnectionID , or the way you get the SessionID from HTTPPTntX is. Current.Session.SessionID?

  2. Can I set the connection ID programmatically when the client adds it by setting session ID, for example? Can it cause problems for some reason? If so, can you please tell me how to set the connection ID programmatically and what event do I need to do this?

    I saw that the page is reloaded every time, the connection ID is changed to a different grid. How do you set the connection point once and keep it at least for the life of the session?

    The approach works, though the correct approach is built into API: customer. other. Message (message) Also there is no need to get Hub reference inside the Hub. You can always access the current connection ID via connection. Messages can be sent through the connection or the client through the client. All.foo ();

    And you can not set the Connective program if you want to track users to keep a list of users on your server and then navigate through the connection ID site, then reassign them. Have to do.

    Here's a post about users tracking:

No comments:

Post a Comment