Reputation: 25282
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?
Upvotes: 11
Views: 715
Reputation: 494
Use ConnectionStatusStream. This stream OnNexts when the client side SignalR hub proxy events are raised. So we see thing like Connecting, Connected,ConnectionSlow, Reconnecting,Reconnected,Closed,Uninitialized. All of which started out life as events on the SignalR hub proxy, and are turned in to an IObservable stream using one of the many RX factories. In this case IObservable.FromEvent.
Anyway here is the overall ConnectivityStatusViewModel that we use to show the information in the bottom status bar of the app.
Refer this:
Upvotes: 2
Reputation: 18944
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.
Upvotes: 2