-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SignalR client JS doesn't reconnect if fails when starting first time #1962
Comments
That's by design. Reconnect only works if you're already connected. But if the connection failed to start in the first place then it won't auto reconnect. If you'd like to always retry then you can write code like this:
|
Thanks, Any particular reason for that? Just want to know for knowledge. Thanks again |
Because it's a more natual API. If you connect to a service that is down chances are something is really wrong. If you were connected at some point and the connection dropped , signalr will retry for a little bit then give up and disconnect. They are very different scenarios and we try to keep the connection up if there's blips in the network but not when failing to start the connection altogether. That behavior is more predictable. |
Oh... So if the server goes off and doesn't come back, then after trying for a little bit, signalr will give up and won't try to reconnect. To keep trying continuously, I have to use disconnected event. |
yes |
One more weird question, why we need timeout inside disconnected method?. what I understand is, we have added a callback method that gets called when connection is disconnected: "conn.disconncted()". For the first time we call conn.start() to try to connect to the server. but if the server is not available, it will call disconnected method. Now inside this disconnected method, if we again call the conn.start() method, shouldn't it do the same thing again. i.e. shouldn't it try to connect to the server and if fails call disconnected method again ( and continuing the loop util its connected.). I try to test this but it's not behaving in this way (it works is I set timeout), so just want to understand why. Really appreciate your help. Thanks |
Hi
My signalR client in my web page tries to connect to the server in a desktop application.
Issue is when client (web page) tries to connect to the server first time and if the server is not online it fails and doesn't reconnect. But if it connects in first time then after, if server drops off, it automatically tries to reconnect.
Here's code example (client side)
var conn = $.hubConnection('url');
var chub = conn.createHubProxy('myhub');
chub.on('messageReceived', function(msg){
$('#log').after('Message Received : ' + msg);
});
conn.stateChanged(function (state){
if(state.newState == $.signalR.connectionState.reconnecting){
$('#log').after('Reconnecting');
}
else if(state.newState == $.signalR.connectionState.connected){
conn.start().done(function(){
$('#log').after('connected');
}).fail(function(){
$('#log').after('Connection failed.');
});
}
});
conn.start().done(function(){
$('#log').after('connected');
}).fail(function(){
$('#log').after('Connection failed.');
});
});
The text was updated successfully, but these errors were encountered: