Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebSockets work in desktop browsers but fail in Chrome for Android

I've a web app that connects to a service via WebSockets. This app works fine in Chrome/Firefox for desktop, however Chrome for mobile gives the error:

WebSocket connection to 'ws://192.168.0.11:8080/' failed: One or more reserved bits are on: reserved1 = 0, reserved2 = 1, reserved3 = 0

The server uses a recent version of libwebsockets.

This error occurs during the initial connection, whereupon a moderately large pile of JSON data is sent to the client over multiple 2048 byte frames.

The server exposes several different WebSockets. Some of them fail in other ways too:

Could not decode a text frame as UTF-8.

...and...

Unrecognized frame opcode: 6

A pattern that predicts which should fail and which should succeed has not yet revealed itself.

I suspect some kind of framing issue here. I've reviewed the messages in WireShark and they look correct to me. The headers appear to be correct.

Why would this work in desktop Chrome/Firefox but fail in Chrome for Android?

like image 521
Drew Noakes Avatar asked Oct 21 '22 11:10

Drew Noakes


1 Answers

The WireShark packet capture shows there are some frames that spill over two TCP packets. The variation of the error messages suggests that random payload is being interpreted as header. I modified my server to make the max packet size 1024 bytes instead of 2048 bytes which suppressed the bug.

I don't know whether this is a bug in Chrome for Android, or whether the desktop version tolerates some violation of the spec that its mobile cousin will not. I suspect the former.

EDIT On my tablet I was also able to address the problem by going into chrome://flags and enabling experimental WebSocket support.

like image 199
Drew Noakes Avatar answered Oct 23 '22 01:10

Drew Noakes