user1434177
user1434177

Reputation: 1977

signalr catching keep alive failure/disconnects

So I have signalr working all fine, pushing my data to the client no problems. I implemented my own keep alive using an ajax call to keep the connection alive. But I have been reading and there is the option that I am trying:

GlobalHost.Configuration.KeepAlive = TimeSpan.FromSeconds(30);

But my issue is if it fails to send the keep alive how do you capture it on the javascript end?

If this is the server pushing data to keep the connection alive does that mean the client will never know if it has failed?

Or will the javascript throw a connection.error?

I want to be able to pull the clients network cable out, and after XX seconds it display a message saying network connection lost. Atm I have this working using my ajax call but is this possible using the keepalive value?

Upvotes: 2

Views: 1909

Answers (1)

N. Taylor Mullen
N. Taylor Mullen

Reputation: 18311

This is already implemented for every transport except LongPolling.

By default the JS client will go into reconnecting if it has missed 2 keep alives.

If you want to tie into the reconnecting event you can do:

$.connection.hub.reconnecting(function() {
    // Your logic
});

If you want to tie into the event that indicates that the connection MAY go into reconnecting can do:

$.connection.hub.connectionSlow(function() {
    // Your logic
});

Keep in mind by default the client will stop trying to reconnect after a given time and will shift into the disconnected state to avoid unnecessary reconnect events. If you want to ensure that your connection is ALWAYS connected, even if there's down time see my answer here: Client Reconnection

Upvotes: 2

Related Questions