socket.shutdown vs socket.close
asynchronous, python, sockets
Solution
Here's one explanation:
Once a socket is no longer required, the calling program can discard the socket by applying a close subroutine to the socket descriptor. If a reliable delivery socket has data associated with it when a close takes place, the system continues to attempt data transfer. However, if the data is still undelivered, the system discards the data. Should the application program have no use for any pending data, it can use the shutdown subroutine on the socket prior to closing it.
Problem
I recently saw a bit of code that looked like this (with sock being a socket object of course): ``` sock.shutdown(socket.SHUT_RDWR) sock.close() ``` What exactly is the purpose of calling shutdown on the socket and then closing it? If it makes a difference, this socket is being used for non-blocking IO.