Skip to content

Commit

Permalink
IsClientConnected fix from CavemanTcp
Browse files Browse the repository at this point in the history
  • Loading branch information
jchristn committed Jul 4, 2023
1 parent 378a554 commit 94677a6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/SuperSimpleTcp/SimpleTcpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
5 changes: 4 additions & 1 deletion src/SuperSimpleTcp/SimpleTcpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down

0 comments on commit 94677a6

Please sign in to comment.