While developing a server client push mechanism using SignalR I have run into the maximum concurrent connections problem. I.e. each browser process only supports around 6 concurrent connections to the same domain.
I am currently keeping track of which users are associated with which connections and after a user has three open connections I would like to force additional connections from the same user to use long polling for a transport as opposed to web sockets. In this way I hope to avoid the problem of running out of connections entirely.
I could always do this on the client with the server providing a non SignalR mechanism to inform the client if they have run out of web socket connections and the client could then specify long polling when it opens the SignalR connection but this seems inefficient. I would really like to set the transport as appropriate when the connection opens.
Something like the following in the hub class.
/// <summary>
/// Chooses the correct transport depending on a users connections
/// </summary>
public override Task OnConnected()
{
if(CanOpenWebSocketsConnection(Context.User.Identity.Name))
{
Connection.Transport = Connections.WebSockets;
}
else
{
Connection.Transport = Connections.LongPolling;
}
return base.OnConnected();
}