Add a handler to close the socket