-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Since reconnect is gone, when using WebSocket as transport layer what is the advisable way for attempting to maintain a connection always on (by attempting reconnection when connection drop is detected)?
It is more like a documentation issue since I didn't find it in documentation.
On server side I have set a KeepAlive of 3 seconds. I have also seen a NegotiateTimeout property. What is it for?
services.AddSignalR(
options =>
{
options.KeepAliveInterval = TimeSpan.FromSeconds(3);
//What is this for?
//options.NegotiateTimeout
});
On client side I have requested for WebSockets with KeepAlive 3 seconds.
HubConnection = new HubConnectionBuilder()
.WithTransport(Microsoft.AspNetCore.Sockets.TransportType.WebSockets)
.WithWebSocketOptions(a => a.KeepAliveInterval = TimeSpan.FromSeconds(3))
.Build();
There is also ServerTimeout option. What is it for?
HubConnection.ServerTimeout = TimeSpan.FromSeconds(9);
I am currently handling the closing event and performing following actions:
await HubConnection.StopAsync();
await Task.Delay(2000);
HubConnection = new HubConnectionBuilder()
.WithTransport(Microsoft.AspNetCore.Sockets.TransportType.WebSockets)
.WithWebSocketOptions(a => a.KeepAliveInterval = TimeSpan.FromSeconds(3))
.Build();
//subscribe to events
await HubConnection.StartAsync();
Is this the correct way to do it, by building a new HubConnection on closing?
Before StopAsync() and starting it again I placed a 2 seconds delay. Should I keep it?