socket.io-client-csharp icon indicating copy to clipboard operation
socket.io-client-csharp copied to clipboard

detecting disconnects

Open Jakobi-mirsk opened this issue 4 years ago • 9 comments

We are seeing that sometimes we do not get notified of disconnects. We are using the default values for reconnection. The server side (made in java-script) is getting notified when the client is not connected anymore. Is there anything we should keep in mind regarding the reconnection mechanism? It is not all the time we see this problem. Sometimes it works and sometimes it doesn't.

Jakobi-mirsk avatar Oct 27 '21 08:10 Jakobi-mirsk

These reasons will cause the client to no longer try to reconnect:

  1. The server has forcefully disconnected the socket with socket.disconnect()
  2. The client calls DisconnecdAsync()
  3. The reconnection counter is greater than Options.ReconnectionAttempts
  4. When Connecting, an uncaught exception is thrown

The default value of Options.Reconnection is true, in other cases, the client will keep trying to reconnect until the connection is successful or the above situations occur.

btw, are you using the latest version of the client library?

doghappy avatar Oct 28 '21 02:10 doghappy

hi I am using version 3.0.3 These are my options: options.Reconnection = true; options.ReconnectionAttempts = int.MaxValue; options.ReconnectionDelay = 1000; options.ReconnectionDelayMax = 5000; options.RandomizationFactor = 0.5;

If the server is disconnecting, would the OnDisconnected event fire? If and uncaught exception is thrown during connecting, would the OnError event fire?

Jakobi-mirsk avatar Oct 28 '21 06:10 Jakobi-mirsk

If the server is disconnecting, would the OnDisconnected event fire?

yeah

If and uncaught exception is thrown during connecting, would the OnError event fire?

no, it is fired upon a connection error. https://github.com/doghappy/socket.io-client-csharp/issues/231

doghappy avatar Oct 28 '21 06:10 doghappy

H, thank for the quick answers If the client is never sending but only receiving data from the server. how will it know, when the connection is down for some reason?

Jakobi-mirsk avatar Oct 28 '21 10:10 Jakobi-mirsk

socket.OnDisconnected+= Socket_OnDisconnected;

...

private void Socket_OnDisconnected(object sender, string e)
{
    Console.WriteLine("reason: " + e);
}

doghappy avatar Oct 28 '21 10:10 doghappy

Okay. I cannot rule out that there is something wrong with the server but we have to client that connect to the server on the same event and receives the same data. Only one of the clients did not receive any data for a long time. That is the reason I believe that there is something wrong with the connection.

Jakobi-mirsk avatar Oct 28 '21 10:10 Jakobi-mirsk

is there any way to enable some debug output in the library?

Jakobi-mirsk avatar Oct 28 '21 14:10 Jakobi-mirsk

You need to remove the reference from NuGet first, then clone this repo and add SocketIOClient.csproj to your project.

You can use Debug or other

https://github.com/doghappy/socket.io-client-csharp/blob/3149107ddd512a8fa68d3f15b80bdf4330910a37/src/SocketIOClient/Transport/TransportRouter.cs#L188

Of course, you can also use breakpoint debugging

doghappy avatar Oct 29 '21 01:10 doghappy

i have similiar issue after i got connected i turned off internet (on the client) and only after ~50 seconds i got disconnected even after doing this:

TimeSpan interval = new TimeSpan(0, 0, 10); //to get 10 seconds
SocketIOOptions options = new SocketIOOptions();
options.Reconnection = false;
options.ConnectionTimeout = interval;

and i didnt got any message on client.OnError and i tried it without putting value in ConnectionTimeout i tried that too:

socket.OnDisconnected+= Socket_OnDisconnected;

...

private void Socket_OnDisconnected(object sender, string e)
{
    Console.WriteLine("reason: " + e);
}

i got this: reason: transport close is there any way to get disconnected message faster (without adding client.DisconnectAsync();)?

oshere1111 avatar Nov 04 '21 11:11 oshere1111