Close properly the socket