I have two software components working in tandem - a Visual Studio C# chat application I made, which connects via a TCP NetworkStream to a Node.js application which is hosting a very simple TCP server.
The C# application sends messages via the TCP NetworkStream to the server, and everything works well, until I close the application (the actual process is relatively unimportant, but I've listed it here and included a short gif for clarity):
First, I start up the Node.js TCP server
Then the C# Application starts and opens up a TCP NetworkStream to the Node.js server
I type the message 'Hello!' into the C# app's input and hit 'Send'
The message is recieved by the TCP server
However when I close my C# application, I get an
ECONNRESET
error
I'm closing the NetworkStream on the client side using NetworkStream.Close()
which, as @RonBeyer pointed out, is ill-advised. According to MSDN it:
Closes the current stream and releases any resources (such as sockets and file handles) associated with the current stream. Instead of calling this method, ensure that the stream is properly disposed.
I assume this is done with the using
keyword in C# (which I am pretty unfamiliar with, given my novice understanding of the language).
BUT I DIGRESS. What I know is that an ECONNRESET
error is caused by an abrupt closure of the socket / stream. The peculiar thing is, disregarding the ECONNRESET
error on the server allows the server to accept new connections seemingly unperturbed.
So my question is:
- does ignoring the error even matter in this context? Are there any possible implications I'm not seeing here?
- and if it does/there are, what problems is it causing under the surface (undisposed resources etc.)?
I say this because the function of the server (to accept new TCP connections) remains uninterrupted, so it seems to make no difference superficially. Any expertise on the subject would be really helpful.
Thanks in advance!