From 94677a671107290816b4a5f09875f2fa42aae587 Mon Sep 17 00:00:00 2001 From: Joel Christner Date: Tue, 4 Jul 2023 10:22:42 -0700 Subject: [PATCH] IsClientConnected fix from CavemanTcp --- src/SuperSimpleTcp/SimpleTcpClient.cs | 2 ++ src/SuperSimpleTcp/SimpleTcpServer.cs | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/SuperSimpleTcp/SimpleTcpClient.cs b/src/SuperSimpleTcp/SimpleTcpClient.cs index 6d0c39a..1137d62 100644 --- a/src/SuperSimpleTcp/SimpleTcpClient.cs +++ b/src/SuperSimpleTcp/SimpleTcpClient.cs @@ -1131,11 +1131,13 @@ private void EnableKeepalives() #if NETCOREAPP3_1_OR_GREATER || NET6_0_OR_GREATER // NETCOREAPP3_1_OR_GREATER catches .NET 5.0 + _client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true); _client.Client.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveTime, _keepalive.TcpKeepAliveTime); _client.Client.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveInterval, _keepalive.TcpKeepAliveInterval); // Windows 10 version 1703 or later + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Environment.OSVersion.Version >= new Version(10, 0, 15063)) { diff --git a/src/SuperSimpleTcp/SimpleTcpServer.cs b/src/SuperSimpleTcp/SimpleTcpServer.cs index e2aaf69..a3d3487 100644 --- a/src/SuperSimpleTcp/SimpleTcpServer.cs +++ b/src/SuperSimpleTcp/SimpleTcpServer.cs @@ -1192,13 +1192,16 @@ private void EnableKeepalives(TcpClient client) { try { -#if NETCOREAPP || NET5_0_OR_GREATER +#if NETCOREAPP3_1_OR_GREATER || NET6_0_OR_GREATER + + // NETCOREAPP3_1_OR_GREATER catches .NET 5.0 client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true); client.Client.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveTime, _keepalive.TcpKeepAliveTime); client.Client.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveInterval, _keepalive.TcpKeepAliveInterval); // Windows 10 version 1703 or later + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Environment.OSVersion.Version >= new Version(10, 0, 15063)) {