Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot get websocket connection to work in Chrome 19

I have a websocket client/server that works perfectly with Firefox and Chrome 18. It does not work with Chrome 19 beta. I suspect it is due to this browser now using a deflate-frame extension which my server doesn't support.

Chrome 19 beta is sending this in its handshake: "Sec-WebSocket-Extensions: x-webkit-deflate-frame"

I have my server sending back: "Sec-WebSocket-Extensions: "

But either this isn't the proper way to reject the extension or there is something else wrong that I'm not catching. This is the only thing in the handshake that is different from what I see coming from the working browsers.

Edit: Here is some additional information. These are the handshakes as captured by Wireshark.


The handshake using Firefox 12:

GET /chatserver HTTP/1.1
Host: (omitted for this post)
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Connection: keep-alive, Upgrade
Sec-WebSocket-Version: 13
Origin: (omitted for this post)
Sec-WebSocket-Key: 2TKm4ozUQdNP17Lobt7IBg==
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: pSUB3BT9YUUd9n3mOeWY/1uVqJE=


The handshake using Chrome 18:

GET /chatserver HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Host: (omitted for this post)
Origin: (omitted for this post)
Sec-WebSocket-Key: zuHLEC8pGvAMadarhCLXFA==
Sec-WebSocket-Version: 13

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: LMBSq6Bk9Kiv+zAbQlAL899pfzc=


The handshake using Chrome 19:

GET /chatserver HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Host: (omitted for this post)
Origin: (omitted for this post)
Sec-WebSocket-Key: TbwnVcuUiqGgZn7hxvxzvQ==
Sec-WebSocket-Version: 13
Sec-WebSocket-Extensions: x-webkit-deflate-frame

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: D45BJ+Vfydy1Upcs3Hze/nuiaS8=
Sec-WebSocket-Extensions:


All server responses have \r\n line-endings and include an extra \r\n at the end of message.

FF12 and Chrome18 work -- Chrome19 does not work. In Chrome19, the very next packet after the server handshake response is a FIN/ACK. The connection is closed.

nb. I have also tried using a hyphen as the Sec-WebSocket-Extensions value but that didn't work either.

like image 857
Aaron Avatar asked May 04 '12 22:05

Aaron


1 Answers

Found the problem.

Firstly, the blank Sec-WebSocket-Extensions entry in the server response was producing a "Invalid UTF-8 sequence in header value" error. After removing that entry, the remaining error was "A server must not mask any frames that it sends to the client."

Indeed, my server implementation (a highly-modified version of PHPWebSocket) defaults to masking the frames it sends. Changing this default behavior fixed the problem and the websocket connection now works in Chrome 19.

Adding the PHPWebSocket tag to this question since it is an issue with that project.

like image 129
Aaron Avatar answered Oct 23 '22 03:10

Aaron