Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Websockify error "Client must support 'binary' or 'base64' protocol"

Tags:

websocket

I'm trying to use websockify to allow javascript executed in a browser to talk to my hand-written server. When using the latest versions of Chrome and Firefox, I get the following error message from websockify: Client must support 'binary' or 'base64' protocol

After looking at the code, I've determined that websockify delivers this message and closes the socket whenever both of these protocols fail to appear under the Sec-Websocket-Protocol header received from the client. When I look at the raw data transmitted by Chrome it doesn't even send this header. Is this a problem with Chrome or websockify, or am I failing to provide some information when opening the websocket in my javascript? Or is there some other explanation?

like image 538
flancor Avatar asked Apr 12 '13 03:04

flancor


1 Answers

You need to provide the protocol list as part of the object constructor:

var ws = new WebSocket(uri, ['binary', 'base64']);

If you use the websock.js library included with websockify then it will handle this for you. However, note that websock.js does not provide the standard WebSocket API but rather a streaming oriented API. Even if you use a raw WebSocket connection to websockify, note that you will still need to do message reconstruction because normal TCP does not have a concept of messages so the messages chunking from onmessage will be essentially "arbitrary".

like image 69
kanaka Avatar answered Oct 04 '22 07:10

kanaka