protected function handleHandshake($data)
    {
        $handshake = new Net_Notifier_WebSocket_Handshake();

        try {
            $response = $handshake->receive(
                $data,
                $this->handshakeNonce,
                array(Net_Notifier_WebSocket::PROTOCOL)
            );

            // for client-connecting to server handshakes, we need to send the
            // Sec-WebSocket-Accept response.
            if ($response !== null) {
                $this->send($response);
            }

            $this->state = self::STATE_OPEN;
        } catch (Net_Notifier_WebSocket_HandshakeFailureException $e) {
            // fail the WebSocket connection
            $this->close();

            // continue to throw exception so it may be logged/reported
            throw $e;
        }
    }