The shutdown() function
As we've just seen, TCP connections are torn down in two steps. The first one side sends a FIN message, and then the other side does. However, each side is allowed to continue to send data until it has sent its own FIN message.
We've used the close() function (closesocket() on Windows) to disconnect sockets because of its simplicity. The close() function, however, closes both sides of a socket. If you use close() in your application, and the remote peer tries to send more data, it will cause an error. Your system will then transmit a Reset (RST) message to indicate to the peer that the connection was not closed in an orderly manner.
If you want to close your sending channel, but still leave the option for receiving ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access