Nenad
Nenad

Reputation: 301

Signalr stops doing Callbacks after some minutes

I am using signalr 0.4 on an aspx-Page,

var hub = $.connection.FooHub;

hub.disconnected(function () {                
            log("Server has disconnected");
        });

hub.ShowInfo = function (Info) { .... }

$("#Button1").click(function () {
            hub.FooFunction('foo');
        });

$.connection.hub.start();

The Hub is defined as :

public class FooHub : Hub, IDisconnect
{    
    ~FooHub()
    {
        log.Debug("FooHub Destroy");
    }
    public FooHub()
    {
        log.Debug("FooHub Startup");
    }    
    public bool FooFunction(string stuff)
    {
        log.Debug("Hub FooFunction");
        Clients.ShowInfo(someInfo);
        return true;
    }
    public Task Disconnect()
    {
        // Query the database to find the user by it's client id etc. etc.
        MyController.Disconnect(Context.ConnectionId);
        log.Debug("Hub Disconnnect " + Context.ConnectionId);
        return null;
    }
   ......
}

When i open the page and immediately click on Button1
it calls the Hub which in turn calls the ShowInfo-function on the page.
With Firebug i can see that signalr is using long-polling for the communcation. So everything works as expected.

But when i then wait a couple of minutes
i see that

however on the Page there is no new connection
Firebug shows the old one still being executed
and when i then click on the Button -

Is this a bug in SignalR or do i have to do something else to get the ShowInfo-call?

Update (Possible answer):

It was using a Forever-Frame and not long-polling.

In addition, the problem seems to happen mostly when using mobile internet (usb-stick) and Firefox.

Changing the transport to long-Polling seems to fix this issue.

Upvotes: 7

Views: 2171

Answers (2)

Trystan Spangler
Trystan Spangler

Reputation: 1769

You mention switching to long polling instead of using a forever frame but didn't say how to do that. You can specify which transports to try when starting the connection.

connection.start({ transport: ['longPolling','webSockets'] });

See https://github.com/SignalR/SignalR/wiki/SignalR-JS-Client for more options.

Upvotes: 1

Pavan Josyula
Pavan Josyula

Reputation: 1375

Did u look at this https://github.com/SignalR/SignalR/wiki/Configuring-SignalR Try this see. To me as per your code every thing seems to be OK. Also can you test the same in Chrome and see whats happening.

Upvotes: 0

Related Questions