chronoxor / NetCoreServer

Ultra fast and low latency asynchronous socket server & client C# .NET Core library with support TCP, SSL, UDP, HTTP, HTTPS, WebSocket protocols and 10K connections problem solution
https://chronoxor.github.io/NetCoreServer
MIT License
2.81k stars 583 forks source link

TcpServer / TcpClient OptionKeepAlive have no effect #295

Open bearyung opened 7 months ago

bearyung commented 7 months ago

I have setup the OptionKeepAlive in both TcpServer and TcpClient, the client successfully connect to the server.

However, when I turn off the router to test the keepalive feature, after the time (60 seconds), the client's OnDisconnected() and OnError() have not been triggered, and the server TcpSession's OnDisconnected() and OnError() also have not triggered.

ChatServer.cs

public ChatServer(IPAddress address, int port) : base(address, port)
    {
        // keepalive settings
        OptionKeepAlive = true;
        OptionTcpKeepAliveTime = 60;
        OptionTcpKeepAliveRetryCount = 10;
        OptionTcpKeepAliveInterval = 1;
    }

ChatClient.cs

public ChatClient(string address, int port) : base(address, port)
    {
        // keepalive settings
        OptionKeepAlive = true;
        OptionTcpKeepAliveTime = 60;
        OptionTcpKeepAliveRetryCount = 10;
        OptionTcpKeepAliveInterval = 1;
    }

Would like to know what is the correct way to setup the keepalive so the application can be notified once the connection has been killed in the socket level. Thank you.

Runtime: .NET 8.0 OS: Mac OS 14.4.1 (23E224) IDE: JetBrains Rider 2024.1

iBoundary commented 6 months ago

I also encountered this issue. Have you resolved it now? @bearyung @chronoxor

bearyung commented 6 months ago

I also encountered this issue. Have you resolved it now? @bearyung @chronoxor

No, I have implemented my own heartbeat logic as a workaround.