Gracefully close the socket