You might want to use the pinging function, which will fail if the TCP connection fails. Use this code to add an extension method to Socket:
using System.Net.Sockets;
namespace Server.Sockets {
public static class SocketExtensions {
public static bool IsConnected(this Socket socket) {
try {
return !(socket.Poll(1, SelectMode.SelectRead) && socket.Available == 0);
} catch(SocketException) {
return false;
}
}
}
}
false, . , , , SocketExceptions on Reveice/Send.
, , , , .
, , , .
:
if (!socket.IsConnected()) {
}