SignalR - how to reconnect client to server (how to restart SignalR)

Ryan picture Ryan · Sep 24, 2012 · Viewed 10.2k times · Source

I have the following problem with SignalR with users accessing my website from a mobile device. The problem is that when the phone locks or the user goes to another app, the Disconnect() method is fired on the server (I try sending a message to the server and waiting for it to reply trough SignalR but there is no reply from the server after the Disconnect method is fired on server). After this it seams as the client is no more connected to the server.

How can the client tell the server that it is back?

Answer

N. Taylor Mullen picture N. Taylor Mullen · Sep 27, 2012

You can stop the connection:

$.connection.hub.stop() 

and then restart it via

$.connection.hub.start();

In the next version of SignalR we will take care of this for you, but for the interim you will have to manage it yourself. I'd recommend detecting on the client if the server is dead and then running the stop -> start.