I have the following requirement for my application: a connection opens between JavaScript (client) and the server (ASP.NET). This connection must be able to send data back & forth for a medium amount of time and remain stateful (unlike REST calls) until it's closed. That is to say, for the duration of the connection, the client basically has affinity (in a web-farm scenario) with the server.
I have read a lot about SignalR and WebSockets in general, but I can't figure out if this is how it operates or not.
I do not care about server->server munication between servers in the web-farm, as this has already been solved with code. I only need the JS client and the server it initially contacts to stay in contact for the duration of the connection.
Is this how it works, and if not, is this possible? In addition, if it is possible, how can I store information in memory for the duration of the connection across multiple calls/broadcasts?
I have the following requirement for my application: a connection opens between JavaScript (client) and the server (ASP.NET). This connection must be able to send data back & forth for a medium amount of time and remain stateful (unlike REST calls) until it's closed. That is to say, for the duration of the connection, the client basically has affinity (in a web-farm scenario) with the server.
I have read a lot about SignalR and WebSockets in general, but I can't figure out if this is how it operates or not.
I do not care about server->server munication between servers in the web-farm, as this has already been solved with code. I only need the JS client and the server it initially contacts to stay in contact for the duration of the connection.
Is this how it works, and if not, is this possible? In addition, if it is possible, how can I store information in memory for the duration of the connection across multiple calls/broadcasts?
Share Improve this question asked Feb 19, 2014 at 23:08 automatonautomaton 3,1685 gold badges31 silver badges40 bronze badges1 Answer
Reset to default 7Keep in mind, that although SignalR does transparently lots of things for you, the 4 underlying transports are quite different.
Only WebSockets and SSE are persistent connections. ForeverFrame and LongPolling are repetitive HTTP requests, and therefore if you have several servers load balanced in a round robin fashion, you have no control on where each call goes.
A solution is to use a load balancer with sticky sessions. This kind of load balancers will look for specific cookies in the HTTP request to set an affinity for a particular server.
Other solution is to use the SignalR backplane, so you do not mind where your requests go, the backplane ensures the connection gets the right messages:
http://www.asp/signalr/overview/signalr-20/performance-and-scaling/scaleout-in-signalr
Each server instance connects to the backplane through the bus. When a message is sent, it goes to the backplane, and the backplane sends it to every server. When a server gets a message from the backplane, it puts the message in its local cache. The server then delivers messages to clients from its local cache.
For each client connection, the client’s progress in reading the message stream is tracked using a cursor. (A cursor represents a position in the message stream.) If a client disconnects and then reconnects, it asks the bus for any messages that arrived after the client’s cursor value. The same thing happens when a connection uses long polling. After a long poll request pletes, the client opens a new connection and asks for messages that arrived after the cursor.