I have a simple program that uses TcpClient and SslStream to write data to a socket.
To test it, I ran the program overnight, so that my program opened the connection, didn’t write anything for a long time, so the firewall or the remote server will close the connection. This morning I looked at TCPView and confirmed that the connection was closed, and then informed my program about writing to the socket.
No exception was thrown on the record. However, the following Write made this exception as expected: "System.IO.IOException: Failed to write data to transport connection: existing connection was forcibly closed by the remote host"
I see why TcpClient.Connected can return True even if it is not really connected, but why Write does not throw an exception in the connection that was actually closed (as checked in TCPView)?
source
share