I have an SSL-connection managed with TcpClient/SslStream. Every 10 seconds I send a heartbeat-type request to keep it fresh:
try
{
this.sslStream.Write(byteArray, 0, byteArray.Length);
}
catch (Exception exception)
{
this.log("[exception] (thread " + this.tableRow.ToString() + ") ApiThread.PostMessage(" + _url + "): " + exception.ToString());
}
The request is an HTTP-type one.
After some period of time (it may be 30 seconds or 10 minutes) the connection is broken and I get an exception:
System.IO.IOException: Unable to write data to the transport connection: An established connection was aborted by the software in your host machine.
Well, I've been reading StackOverflow and googling for solutions. Generally people suggest:
1) To look for a firewall which breaks the connection. There is no firewall. Tested in 2 different networks.
2) To activate/deactivate KeepAlive option:
this.tcpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true/false);
Didn't help.
What I'm not doing is that I don't read the server response, and there definitely is one, I just don't need that response for my messages. Is that possible that by not reading the incoming messages I somehow mess up with the read-buffer (by not emptying it from time to time), hence making Windows to close the connection?
What are the other possible causes for the connection closure? It's not a random connection closure but a pattern. No connection lives for more than 10-15 minutes.