Dear readers,
I have a windows service (client) which basically should be up 24/7, however sometimes the connection drops.
Basically what happens is that i send a command to the service, and i will get the response "An existing connection was forcibly closed by the remote host".
Now what i would expect is that the IsConnected function (called from timer) notices that the connection has dropped and restarts the connection but it doesn't actually notice that the connection has closed.
private bool IsConnected(Socket socket)
{
try
{
return !(socket.Poll(100, SelectMode.SelectRead) && socket.Available == 0);
}
catch (SocketException) { return false; }
}
But it doesn't seem to work..
Another idea was to actually send data as a keep alive, but if the timer event raises while for example the socket is in the middle of transferring a file it goes to hell.
Socket:
clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
clientSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, 1);
IPEndPoint ipEnd = new IPEndPoint(IPAddress.Loopback, 1500);
clientSocket.Connect(ipEnd);
Any suggestions are very welcome,
Thanks!