Your question suggests you have some misunderstanding about how to use sockets.
The Shutdown()
method is not the same as the Close()
method. They both are required. The Shutdown()
method is what you use to inform the remote endpoint that you're done sending. Once both ends have shutdown the socket, then you can close the socket. Not before.
The Close()
method is there to free up the unmanaged resources, i.e. the Windows socket handle that the .NET Socket
class abstracts. Call this method only after you have gracefully shutdown the connection, or after an exception occurs while using the socket (at which point, the socket is no longer usable).
You don't need to call Dispose()
at all. All it does is call the Close()
method. Alternatively, call Dispose()
instead of calling Close()
. Either is fine. You don't need to call both.
It is true that if you call neither Close()
nor Dispose()
, at some point the garbage collector might get around to finalizing the object, which will dispose it for you. But that's not guaranteed, not when it will happen nor even if it will ever happen.
Note that if you want to reconnect faster, you need to do the graceful shutdown, even though it seems like that's more work. If you just close the socket, or you close it after calling Shutdown()
but before waiting for the remote endpoint to also shutdown the connection, your socket will wind up in a waiting state that prevents reuse of that port and socket resources. The fastest way to reset your connection state and get reconnected again is to use the API correctly.
I always recommend to people new to the socket API to read the Winsock Programmer's FAQ. It's not written for the .NET audience, but almost all of the information there is critically useful to anyone trying to learn how to use any network socket API.