We are attempting to use SignalR in an low-bandwidth environment where the connection to the backend server can come and go randomly, and we want our web application to respond appropriately.
It looks like this connection API has been in flux over the past year, but in accordance with the latest documentation, I have tried hooking up to $.connection.hub.stateChanged to detect changes in the connection status, and I get a couple hits on startup when the client goes from disconnected -> connecting -> connected, but when I stop the server, the event handler does not fire, and when I start the server again, the real-time messaging is no longer working.
To test this scenario, I am on Windows 7 running the ASP.NET web server in IIS and the web client is running in Google Chrome. Once the site is running, and messages are being exchanged, I kill the website in IIS, and the messages stop but the client does not receive any notification.
Here's a quick snippet (using TypeScript):
$.connection.hub.stateChanged((change) => {
console.log("state changed...");
console.log(change);
if (change.newState === $.signalR.connectionState.reconnecting) {
this.raise('action:disconnected');
}
else if (change.newState === $.signalR.connectionState.connected) {
this.raise('action:connected');
}
});
Any guidance would be much appreciated, thanks!
-Jeremy
What version of SignalR are you using? In the latest (and ones before it) the server going offline is immediately detected and the state change is raised with the reconnecting flag.
To kill the server, I assume you mean shut down IIS .e.g iisreset. Stopping the website in inetmgr does NOT shut the site down, it merely removes the Http.sys binding for that port. See https://github.com/SignalR/SignalR/issues/1148 for more info.
If you want to simulate the server going down kill w3wp.