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.
Client disconnection scenarios When the user closes a browser window or tab, or navigates to a new page or refreshes the page, the SignalR connection immediately ends because SignalR client code handles that browser event for you and calls the Stop method.
SignalR requires that all HTTP requests for a specific connection be handled by the same server process. When SignalR is running on a server farm (multiple servers), "sticky sessions" must be used. "Sticky sessions" are also called session affinity by some load balancers.
In the default mode, the app server creates five server connections with Azure SignalR Service. The app server uses the Azure SignalR Service SDK by default. In the following performance test results, server connections are increased to 15 (or more for broadcasting and sending a message to a big group).
SignalR is a Microsoft framework specifically designed to facilitate real-time client/server communication. It provides an effective implementation of long polling that doesn't have a deep impact on the server, and at the same time ensures that clients are appropriately updated about what's going on remotely.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With