Note that there are some explanatory texts on larger screens.

plurals
  1. POImplementing handshake for hybi-17
    text
    copied!<p>I'm trying to develop the <strong>handshake</strong> for <strong>websocket hybi-17 protocol</strong> (<a href="http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-17" rel="nofollow">http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-17</a>). According to that draft, I made the following code for the client (user-agent):</p> <pre><code>var host = 'ws://localhost/server.php'; if ('MozWebSocket' in window) ws = new MozWebSocket (host); else ws = new WebSocket (host); </code></pre> <p>and this code for the server (I skipped the socket initialization/management part):</p> <pre><code>$key = $value = null; preg_match ("#Sec-WebSocket-Key: (.*?)\r\n#", $buffer, $match) &amp;&amp; $key = $match[1]; $key .= "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; $key = sha1 ($key); $key = pack ('H*', $key); $key = base64_encode ($key); $value = "HTTP/1.1 101 Switching Protocols\r\n" . "Upgrade: websocket\r\n" . "Connection: Upgrade\r\n" . "Sec-WebSocket-Accept: {$key}"; socket_write ($socket, $value, strlen ($value)); </code></pre> <p>Now, following an example, starting with the client request (simply done with 'new MozWebSocket (host)' call):</p> <pre><code>GET /server.php HTTP/1.1 Host: localhost User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: it-it,it;q=0.8,en-us;q=0.5,en;q=0.3 Accept-Encoding: gzip, deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Connection: keep-alive, Upgrade Sec-WebSocket-Version: 8 Sec-WebSocket-Origin: http://localhost Sec-WebSocket-Extensions: deflate-stream Sec-WebSocket-Key: oqFCBULD7k+BM41Bc3VEeA== Pragma: no-cache Cache-Control: no-cache Upgrade: websocket </code></pre> <p>The server response (echoed in the local shell, as a debug line):</p> <pre><code>HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: TlKc0Ck7WpqsLhMm/QXABMQWARk= </code></pre> <p>I followed what specified in the IETF hybi-17 draft but the client request <em>is still pending</em> and there's no real connection between client and server.</p> <p>What's wrong? What I have to do more?</p> <p>Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload