Java: working handshake