I'm working with SignalR under very specific set of network conditions (a crazy proxy). So sockets do not work at all and I have to use long-polling. When I refresh a page it seems to work for a while but then the first Disconnect happens. I'm trying to automatically reconnect on disconnected event and the following pattern:
This behaviour seems weird. Is there anything I can do to improve it?
If a server does not become available within the disconnect timeout period, the SignalR connection ends. In this scenario, the Closed event ( disconnected in JavaScript clients) is raised on the client but OnDisconnected is never called on the server.
To test reconnect after the server goes down use iisreset. To simulate client connection dropping (good luck) pull the network cable :) Pulling the network cable won't accurately simulate a client connection dropping when you're using Azure SignalR Service.
hub. stop(). done(function() { alert('stopped'); });
Timeout configuration for SignalR can be set in Application_Start method of Global class in Global. asax. cs file. // Wait a maximum of 30 minutes after a transport connection is lost // before raising the Disconnected event to terminate the SignalR connection.
Assume the tips available in Understanding and Handling Connection Lifetime Events in SignalR where you can employ good solutions to handle connection lifetime based on the network problem. Furthermore, In SignalR's issues I found the following solution for you which works with long-polling too.
You can set the KeepAlive
property on the ConfigurationManager
and SignalR will send an empty frame of data (based on the transport) on the specified interval to keep the connection alive (look at Allow host to specify keep alive times). The current time-out mechanism makes the streaming protocols no different.
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