public void close() throws IOException {
   if (in != null) {
     in.close();
   }
   if (out != null) {
     out.close();
   }
   if (socket != null && !socket.isClosed()) {
     socket.close();
   }
 }