NetCoreServer icon indicating copy to clipboard operation
NetCoreServer copied to clipboard

TcpServer / TcpClient OptionKeepAlive have no effect

Open bearyung opened this issue 2 months ago • 2 comments

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

bearyung avatar Apr 18 '24 15:04 bearyung

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

iBoundary avatar May 06 '24 08:05 iBoundary

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

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

bearyung avatar May 17 '24 06:05 bearyung