frmqit
asked on
SignalR reconnection problem
Hi everyone
I' am trying to implement some reconnction handling for my signalR websocket. Therefore
I register the stateChanged event of signalR and if new state is reconnecting, I call a initial function which will return me some data. Below I added my script:
If I turn off my wlan and turn it on again, the reconnecting event should get fired, calling getInit which will cause dataInit to be executed.
This works fine the first time I do so. But after the second time I turn off and on my wlan, the stateChanged event never accours again.
Is this a known issue and does someone know how to fix it?
Any help would be much appreciated.
I' am trying to implement some reconnction handling for my signalR websocket. Therefore
I register the stateChanged event of signalR and if new state is reconnecting, I call a initial function which will return me some data. Below I added my script:
$(document).ready(function () {
$.connection.hub.stateChanged(function (change) {
if (change.newState == 2) //reconnecting
{
$.connection.myHub.getInit();
}
});
$.connection.myHub.dataInit = function (data) {
dosomething(data);
};
$.connection.hub.start();
});
If I turn off my wlan and turn it on again, the reconnecting event should get fired, calling getInit which will cause dataInit to be executed.
This works fine the first time I do so. But after the second time I turn off and on my wlan, the stateChanged event never accours again.
Is this a known issue and does someone know how to fix it?
Any help would be much appreciated.
ASKER
hi leakim971
I'am debugging with buildin developer tools from Crome.
I now also listening on hub error event and check for disconnected state:
I also set breakpoints. But error event and disconnected doesn't ever accour. But I think you might be right. When the reconnection event accours the first time, a handeled get error accours in log:
http://mydomain.org/signalr/connect?transport=serverSentEvents&connectionId=29f4398b-3093-423f-b568-fc6fd358778e&connectionData=%5B%7B%22name%22%3A%22myHub%22%7D%5D&tid=10
I don't know if this the problem but at the same time the connection seems to be closed and a new connection opens with a different name. In the screenshot I attached you will see the network panel of chrome. When the connection starts, a get with name connect shows and stays open, which obviously is the connection to the websocket. When the reconnect event accours, this connection seems to be closed and a new connection with name signalr opens.
Do you know why this happens and how to solve this problem?
Network.jpg
I'am debugging with buildin developer tools from Crome.
I now also listening on hub error event and check for disconnected state:
$.connection.hub.error(function (error) {
alert("ConnectionError: " + error);
});
$.connection.hub.stateChanged(function (change) {
if (change.newState == 4) //disconnected
{
alert(change.newState);
}
if (change.newState == 2) //reconnecting
{
$.connection.myHub.getInit();
}
});
I also set breakpoints. But error event and disconnected doesn't ever accour. But I think you might be right. When the reconnection event accours the first time, a handeled get error accours in log:
http://mydomain.org/signalr/connect?transport=serverSentEvents&connectionId=29f4398b-3093-423f-b568-fc6fd358778e&connectionData=%5B%7B%22name%22%3A%22myHub%22%7D%5D&tid=10
I don't know if this the problem but at the same time the connection seems to be closed and a new connection opens with a different name. In the screenshot I attached you will see the network panel of chrome. When the connection starts, a get with name connect shows and stays open, which obviously is the connection to the websocket. When the reconnect event accours, this connection seems to be closed and a new connection with name signalr opens.
Do you know why this happens and how to solve this problem?
Network.jpg
ASKER
It looks like I was just too impatient. It looks like it often just needs extremly long until reconnecting gets fired(5 to 10 minutes in my case).
Is there a way to make it faster or might it be just my network causing it to be that slow?
Is there a way to make it faster or might it be just my network causing it to be that slow?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your help. I tested now under other conditions and it works. I guess turning on and off the wlan switch on my laptop isn't a good testing scenario anyway.
check with a javascript debugger for error