Closed Faxmachinen closed 2 years ago
Hmm, I'm not sure I understand why the current code does not work as expected.
According to StackOverflow, Disconnect does the same as Shutdown. This information could of course be outdated but calling both Disconnect and Shutdown seems redundant.
This solves the issue you mentioned?
Microsoft does mention Shutdown
instead of Disconnect
to properly clean up the socket, did your testing show if Disconnect
is necessary?
https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.socket?view=net-5.0
I have not tested it. The official documentation on Disconnect remarks:
To ensure that all data is sent and received before the socket is closed, you should call Shutdown before calling the Disconnect method.
Shutdown should be called before Disconnect on TCP sockets to ensure that data in the socket buffers have been sent.