Note that there are some explanatory texts on larger screens.

plurals
  1. POClient - Server WebSocket handshake
    primarykey
    data
    text
    <p>I'm trying to implement a simple web socket server and client. This is my first time looking at them, so sorry if this question is obvious.</p> <p>I'm using Chrome v15, which I believe uses the 09 (version 8) protocol?</p> <p>I just don't seem to be able to get them to connect. The request I'm getting from the browser is:</p> <pre><code>GET /chat HTTP/1.1 Upgrade: websocket Connection: Upgrade Host: localhost:8181 Sec-WebSocket-Origin: http://localhost:51990 Sec-WebSocket-Key: JFAw5PLk45TodN2ERD1ePA== Sec-WebSocket-Version: 8 Cookie: size=4; CP.mode=B; ASP.NET_SessionId=zzx3d3ajepwwycqjaj1nyex4; .ASPXAUTH=781D3791DC2483756B3DA9FA8E031A9BACD357EBD8FA23B7BCB8BDA6526F28F77FC798A0D4BEC4E2B166700B5C08FA60CBF588D292BFC1D050C9B034522C93ACBEF28BC6D51FDC5B40F6050F03758DA1A3E4D3F7484BC4F7DA3602A5FAFD3023C8D4D5929B69F88DB417CA6F366A83F334807818E2C07E23C0D0993F25B3C9BDE02A; name=Test </code></pre> <p><em>I've noticed that the <code>Sec-WebSocket-Protocol</code> header is missing.</em></p> <p>The response I'm sending looks like this:</p> <pre><code>HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: VAuGgaNDB/reVQpGfDF8KXeZx5o= Sec-WebSocket-Protocol: chat </code></pre> <p>Can anyone shed some light on what I'm doing wrong please?</p> <p><strong>EDIT</strong>: The code I'm using to generate the accept key is:</p> <pre><code>public static String ComputeWebSocketHandshakeSecurityHash09(String secWebSocketKey) { const String MagicKEY = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; String secWebSocketAccept = String.Empty; // 1. Combine the request Sec-WebSocket-Key with magic key. String ret = secWebSocketKey + MagicKEY; // 2. Compute the SHA1 hash SHA1 sha = new SHA1CryptoServiceProvider(); byte[] sha1Hash = sha.ComputeHash(Encoding.UTF8.GetBytes(ret)); // 3. Base64 encode the hash secWebSocketAccept = Convert.ToBase64String(sha1Hash); return secWebSocketAccept; } </code></pre> <p><strong>EDIT</strong>: This is the response code:</p> <pre><code> StringBuilder mResponse = new StringBuilder(); mResponse.Append("HTTP/1.1 101 Switching Protocols" + Environment.NewLine); mResponse.Append("Upgrade: WebSocket" + Environment.NewLine); mResponse.Append("Connection: Upgrade" + Environment.NewLine); mResponse.Append(String.Format("Sec-WebSocket-Accept: {0}", ComputeWebSocketHandshakeSecurityHash09(secKey)) + Environment.NewLine); // Build the response for the client byte[] HandshakeText = Encoding.UTF8.GetBytes(mResponse.ToString()); logger.Log(""); logger.Log("Sending handshake ..."); ConnectionSocket.BeginSend(HandshakeText, 0, HandshakeText.Length, 0, HandshakeFinished, null); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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