Cannot get websocket connection to work in Chrome 19
Asked Answered
M

2

6

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.

Mcculloch answered 4/5, 2012 at 22:4 Comment(0)
M
4

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.

Mcculloch answered 6/5, 2012 at 6:7 Comment(2)
Hi Aaron, Please can you point me where and what to change? I have exactly the same problem, I'm using the same PHP-Websocket and it has suddenly stopped working on the latest version of Chrome.Spectroradiometer
@ClintonGreen: Look for the send function in Connection.php. You will see in the arguments that $masked defaults to true. That argument needs to be false for send to work correctly in Chrome 19+. Sorry for the late reply.Mcculloch
M
2

For Chrome, "Sec-WebSocket-Protocol" header must has value for both server and client side. This is the case for me.

Munda answered 19/11, 2013 at 11:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.