I'm pretty new to socket programming. Our application uses sockets to communicate with a device our company manufactures. We have a problem with the socket sometimes taking a long time to close.
Here's the code that is run when it is time to close the socket:
if (client != null) {
try {
if (client.Connected) {
client.Disconnect(false);
client.Shutdown(SocketShutdown.Both);
}
client.Close();
} catch (SocketException) {
}
client = null;
}
I've read the documentation for the Socket.Shutdown
method and the responses to this question and I'm confused. Will any data that is pending transfer from the remote system to this system, or vice versa, be transferred or abandoned? If the data that is pending transfer is abandoned, what could be delaying the socket's closure?