I did a small C# server application to test the GPRS modem in client mode. Sometimes while working I get a SocketException with ErrorCode equals to 10054, i.e. WSAECONNRESET. Exception occurs during NetworkStream.ReadByte() call and means that existing connection was forcibly closed by the remote host. Okay, but when i use client application instead of modem and call Socket.Close() in it, NetworkStream.ReadByte() on server side simply returns -1.
So whats the difference between situation that caused WSAECONNRESET exception and the situation when client manually closes the socket?
When a connection is closed via Socket.Close(), the peer is informed through the TCP mechanism about this. When the client crashes, is shut down (killed), the host crashes, the connection is interrupted (by a firewall ..) etc. the server is given the exception.
From Microsoft:
WSAECONNRESET (10054)
Connection reset by peer.
An existing connection was forcibly closed by the remote host. This normally results if the peer application on the remote host is suddenly stopped, the host is rebooted, the host or remote network interface is disabled, or the remote host uses a hard close (see setsockopt for more information on the SO_LINGER option on the remote socket). This error may also result if a connection was broken due to keep-alive activity detecting a failure while one or more operations are in progress. Operations that were in progress fail with WSAENETRESET. Subsequent operations fail with WSAECONNRESET.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With