Question

I wrote a websocket server in c++ that works fine with websocket protocol 00 (the one with key1, key2 in handshake header).

Now with the new update I am trying to do the same for the new way handshaking work. Here is my server response to the handshake request:

"HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: " + serverKey + "\r\n\r\n";

in which serverkey is computed correctly. As an example:

handshake request:
GET /test HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Host: 192.168.123.102:8585
Sec-WebSocket-Origin: http://192.168.123.5
Sec-WebSocket-Key: YB0mPvJ5t8ggCeGUWY39uQ==
Sec-WebSocket-Version: 8

handshake response header :
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: xt9iyCNryQTseELUkHPWjzxA2ts=

I also check my algo with the example here http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-08 and it produced the exact same response.

However I still get the following error:
"Error during WebSocket handshake: Sec-WebSocket-Accept mismatch"

I am using chrome 15 as my browser.

Do you have any Idea what goes wrong?

(also in chrome inspector Network, it does not show the response which is the case when it does not accept the handshake (even with older versions))

Was it helpful?

Solution

I actually found out what was the primary problem.

the key that I used for base64 encoding was

YB0mPvJ5t8ggCeGUWY39uQ==
258EAFA5-E914-47DA-95CA-C5AB0DC85B11

instead of

YB0mPvJ5t8ggCeGUWY39uQ==258EAFA5-E914-47DA-95CA-C5AB0DC85B11

an extra \n was the whole problem.

HOWEVER, Now that I receive the Connected message (ws client is successfully connected to ws sever) I cannot send or receive anything. The problem is server side.

DO you know what are the server side changes since older websocket protocol? I only change my handshake respond and it doesnt seem enough.

OTHER TIPS

There is a different framing protocol for when the client sends data. Previously it was quite simple. Now it is much more complicated. Please refer to the websockets rfc6455 spec.

http://tools.ietf.org/html/rfc6455#section-5.2

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top