public function receive($data, $nonce, array $protocols = array())
    {
        $handshake = $this->parseHeaders($data);
        $headers   = $handshake['headers'];

        // get status code from status line
        $status_parts = explode(' ', $handshake['status']);
        if (count($status_parts) > 1) {
            $status = (integer)$status_parts[1];
        } else {
            $status = 400;
        }

        // get method from status line
        $method = $status_parts[0];

        if ($status == '101') {
            $response = $this->receiveServerHandshake(
                $headers,
                $nonce,
                $protocols
            );
        } elseif ($method === 'GET') {
            $response = $this->receiveClientHandshake($headers, $protocols);
        } else {
            $response = "HTTP/1.1 400 Bad Request\r\n\r\n";
        }

        return $response;
    }