doghappy / socket.io-client-csharp

socket.io-client implemention for .NET
MIT License
729 stars 125 forks source link

Connection Timeout after few minutes #261

Open CyxSolutions opened 2 years ago

CyxSolutions commented 2 years ago

So i created a C# Console Application for Monitoring purposes that connects to my SocketIO Server. After 5-10 Minutes the Connection closed (Disconnect Event Triggered Only on Server Side) The Client does not reconnect by itself so it seems like the whole Socket gets terminated? What can be the problem here?

For Debug purposes both client and server run on the same machine.

public static async Task Main()
        {
            var socket = new SocketIO(new Uri("http://localhost/"), new SocketIOOptions
            {
                Reconnection = true,
                ReconnectionAttempts = 10,
                ReconnectionDelay = 1000
            });

            socket.OnConnected += Socket_OnConnected;
            socket.OnPing += Socket_OnPing;
            socket.OnPong += Socket_OnPong;
            socket.OnError += Socket_OnError;
            socket.OnDisconnected += Socket_OnDisconnected;
            socket.OnReconnectAttempt += Socket_OnReconnecting;

            socket.On("ResponseMessage", response => Console.WriteLine(response.GetValue<string>()));
            socket.On("UpdateDeviceInfo", async response => await socket.EmitAsync("registerDeviceInfo", GetDeviceInfo()));
            socket.On("UpdateDeviceProcessor", async response => await socket.EmitAsync("registerDeviceProcessor", GetProccessorInfo()));
            socket.On("UpdateDeviceMemory", async response => await socket.EmitAsync("registerDeviceMemory", GetMemoryInfo()));
            socket.On("UpdateDeviceDrives", async response => await socket.EmitAsync("registerDeviceDrives", GetDriveInfo()));
            socket.On("UpdateDeviceNetwork", async response => await socket.EmitAsync("registerDeviceNetwork", GetNetworkInfo()));
            socket.On("UpdateDeviceGraphics", async response => await socket.EmitAsync("registerDeviceGraphics", GetGraphicsInfo()));
            socket.On("UpdateDevicePrograms", async response => await socket.EmitAsync("registerDevicePrograms", GetPrograms()));

            socket.On("RegisterDevice", async response =>
            {
                await socket.EmitAsync("registerDeviceInfo", GetDeviceInfo());
                await socket.EmitAsync("registerDeviceProcessor", GetProccessorInfo());
                await socket.EmitAsync("registerDeviceMemory", GetMemoryInfo());
                await socket.EmitAsync("registerDeviceDrives", GetDriveInfo());
                await socket.EmitAsync("registerDeviceNetwork", GetNetworkInfo());
                await socket.EmitAsync("registerDeviceGraphics", GetGraphicsInfo());
                await socket.EmitAsync("registerDevicePrograms", GetPrograms());
            });

            await socket.ConnectAsync();
            Console.ReadLine();
        }
doghappy commented 2 years ago

Can you create a reproducible repository? Thank you

WaterskiScoring commented 2 years ago

I would suggestion checking the version of System.Text.Json. I recently had an issue where my program was terminating without an exception after attempting to connect to a SocketIO server. The issued turned out to be the version of a dependency, SystemText.Json. When my project include versions 6.0.1 or 6.0.2 it had this problem. I discovered that using version 6.0.0 worked successfully.

CyxSolutions commented 2 years ago

I think it happens when my Response Function takes to long?

For example the SocketIO Server Requests every installed program on a Windows Machine. The C# Application reads all installed Applications what takes about 20-30 Seconds (while this the connection terminates) and then the Client tries to submit the list of programs what fails as the connection closes.

Probably the Ping Pong / Heartbeat is not working while the application does not accept any command from the socket server while scanning the programs? How can this get fixed?