1

How do I detect when a client is failing to connect (or re-connect) to a Signalr hub?

Is there an event that fires on the js client?

Will
  • 773
  • 1
  • 7
  • 24
  • Apologies, looks like a duplicate... http://stackoverflow.com/questions/10726453/signalr-connect-disconnect-hub-blows-up – Will Oct 05 '12 at 13:55
  • Looks like I commented on my own question to rapidly - having implemented this solution in the link above, it doesn't fire events when I stop my signalr server, at the points I would have expected...any ideas as to the best events to listen to? – Will Oct 05 '12 at 14:35

1 Answers1

3

Responding to your second comment:

Currently in 0.5.3 SignalR does not handle the case when the server goes away. However, this will be/is handled in the next release 1.0alpha.

For the interim I'd recommend pinging the server every 5 seconds and seeing if the request fails. If it fails say 2 times then chances are the server is down and you can handle the logic from there.

If you'd like to see how we do it in the next release here's the link to the github feature: https://github.com/SignalR/SignalR/issues/469

N. Taylor Mullen
  • 18,061
  • 6
  • 49
  • 72
  • Thanks. Having read the new implementation, D Fowler wrote the following...On the client side, we need to figure out what the best event is and whether to separate reconnecting from keepAliveTimeout. As a developer, do you want to write separate logic for each or do you just care that your network connection "went away". How much details does the developer need to make a decision for their app. If we do keep the event separate then I think we need to have a higher level event on the connection that basically means "network down". Maybe reconnecting works just as well. – Will Oct 05 '12 at 18:53
  • If we have several signalr boxes behind a loadbalancer - it would be really handy if the signalr response tells the client that it has no idea who they are, so they can trigger a proper connect again and subscribe to their lost groups; does this make sense? At the moment if a client hits a server that they don't exist on they don't know that the server has no idea what groups they want messages from. – Will Oct 05 '12 at 18:58
  • As far as the client is concerned, it only wants to know if it's disconnected or in reconnecting etc. However, in the situations where a server has no idea who a client is (and the client is claiming that the server should know) the server will pump down a disconnect command to the client in order to force it to do a full start (negotiate etc.). In this situation the developer can write logic to rejoin X many groups. Also, keep in mind that in the next release by default we will not allow auto-rejoining of groups (security issue). Therefore the practice of maintaining them on the client – N. Taylor Mullen Oct 05 '12 at 19:23
  • will become more common. Hope this helps. And here's a link to the auto-rejoining bug: https://github.com/SignalR/SignalR/issues/525 – N. Taylor Mullen Oct 05 '12 at 19:23
  • That sounds like a lot better solution - thanks for the details. Looking forward to the 1.0alpha release... – Will Oct 06 '12 at 10:44