2

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.

Pingguoren
  • 31
  • 4
  • Initially I was running that code on my local computer and on the remote Windows VPS, each time connecting to the web server of interest. Also I was testing that code on my local computer connecting to the local Apache web server. No matter what I do, the connection still breaks. I suppose, there is something going on either on the .NET side or on the Windows sockets side. – Pingguoren May 07 '17 at 17:44
  • I disabled the SSL layer and tried it with just TcpClient. The same thing, connection breaks. Tracing showed nothing of interest: System.Net.Sockets Verbose: 0 : [6532] Socket#51288387::Send() System.Net.Sockets Error: 0 : [6532] Socket#51288387::UpdateStatusAfterSocketError() - ConnectionAborted System.Net.Sockets Error: 0 : [6532] Exception in Socket#51288387::Send - An established connection was aborted by the software in your host machine. – Pingguoren May 07 '17 at 18:28

0 Answers0