/** Handshake with the debuggee */
  void handshake(Socket s, long timeout) throws IOException {
    s.setSoTimeout((int) timeout);

    byte[] hello = "JDWP-Handshake".getBytes("UTF-8");
    s.getOutputStream().write(hello);

    byte[] b = new byte[hello.length];
    int received = 0;
    while (received < hello.length) {
      int n;
      try {
        n = s.getInputStream().read(b, received, hello.length - received);
      } catch (SocketTimeoutException x) {
        throw new IOException("handshake timeout");
      }
      if (n < 0) {
        s.close();
        throw new IOException("handshake failed - connection prematurally closed");
      }
      received += n;
    }
    for (int i = 0; i < hello.length; i++) {
      if (b[i] != hello[i]) {
        throw new IOException("handshake failed - unrecognized message from target VM");
      }
    }

    // disable read timeout
    s.setSoTimeout(0);
  }
 SocketConnection(Socket socket) throws IOException {
   this.socket = socket;
   socket.setTcpNoDelay(true);
   socketInput = socket.getInputStream();
   socketOutput = socket.getOutputStream();
 }