5

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

jeremyalan
  • 4,658
  • 2
  • 29
  • 38
  • Depending on which transport you're using, it can take some time before you'll get any disconnected events. My understanding is that if you're running IIS Express on Windows 7, you're going to be forced into using Long Polling, which means that itmight take a minute or more before the session realizes it's disconnected. How long have you waited to see if the statechanged event fires? – Ken Smith Jan 26 '13 at 07:14
  • I shut down the site in IIS and let it sit idle for awhile, 5 minutes or more probably. I'll run the test again and make sure it sits idle for several minutes. – jeremyalan Jan 26 '13 at 18:54

1 Answers1

5

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.

davidfowl
  • 37,120
  • 7
  • 93
  • 103
  • 1
    I'm using the 1.0 release. I didn't realize that about stopping the site in IIS. I tried stopping the App Pool instead, and the reconnect worked perfectly. Thanks! – jeremyalan Jan 27 '13 at 02:18
  • `Stopping the website in inetmgr does NOT shut the site down, it merely removes the Http.sys binding for that port.` ... wow, oops... – Stefan Aug 08 '17 at 19:21