Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1561
  • Last Modified:

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:
$(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();
});

Open in new window


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.
0
frmqit
Asked:
frmqit
  • 3
  • 2
1 Solution
 
leakim971PluritechnicianCommented:
perhaps you've a javascript error throwed with the disconnexion so the javascript code stop working
check with a javascript debugger for error
0
 
frmqitAuthor Commented:
hi leakim971

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();
        }
    });

Open in new window


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
0
 
frmqitAuthor Commented:
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?
0
 
leakim971PluritechnicianCommented:
To be honest I don't know.
I don't think 5/10 minutes is usual delay so I think it's about something about your network or the "server" part
0
 
frmqitAuthor Commented:
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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now