Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

websocket for binary transfer of data & decode

I was reading through the specification and many examples about usage of websockets. Almost all of them talk about UTF-8 or ascii message transfer using websockets.

The latest Hybi websocket spec requested support for binary transfer. REQ 6 in hybi spec

Also i read somewhere that chrome supports hybi. But latest release Chrome 7.0 works only when draft-hixie is selected in pywebsocket config.

Does any browser have support for hybi spec? Even if it is dev, its ok.

like image 415
vprajan Avatar asked Sep 27 '10 17:09

vprajan


People also ask

Can a single WebSocket handle text and binary data?

WebSocket enables bidirectional, message-oriented streaming of text and binary data between client and server.

What data can be transferred on WebSocket?

You can send the underlying binary data used by a typed array object; its binary data contents are queued in the buffer, increasing the value of bufferedAmount by the requisite number of bytes.

What is WebSocket binary?

binaryType. The WebSocket. binaryType property controls the type of binary data being received over the WebSocket connection.

Can we send JSON data in a WebSocket connection?

To create a WebSocket and open the connection to FME Server use getWebSocketConnection method. The result is an open WebSocket you can use in your application to communicate with FME Server. This example sends a basic JSON object as a string to the server, and displays the response from the server.


1 Answers

It may be a while before non-UTF-8 (i.e. binary) encoding is supported in WebSockets.

I suggest using base64 encode/decode on the client and server. All browsers with WebSockets support have window.atob (base64 decode) and window.btoa (base64 encode). Most languages you might write a WebSockets server in have base64 libraries (i.e. base64 module in python).

If you are wanting to transfer binary data you might be interesting in wsproxy included with noVNC which is a web based VNC client. wsproxy (there is a C and python version) is a WebSockets to generic TCP sockets proxy. It base64 encodes/decodes all traffic to/from the browser. You can use it to connect from a WebSockets capable browser to any type of TCP port.

Note, noVNC has a Javascript implementation of base64 encode/decode because belief it or not, the Javascript version is slightly faster than atob/btoa.

Disclaimer: I created noVNC.

like image 156
kanaka Avatar answered Oct 17 '22 15:10

kanaka