Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Websockets and binary data

As far as i know websockets support binary data transfer. Binary support bug is fixed.

So, are there any websocket servers which support binary data transfer? Socket.io seems to miss this opportunity. Maybe there are some others?

like image 662
Dmitrii Sorin Avatar asked Jul 29 '11 07:07

Dmitrii Sorin


People also ask

Does WebSocket support binary data?

API Gateway WebSocket APIs don't currently support binary frames in incoming message payloads. If a client app sends a binary frame, API Gateway rejects it and disconnects the client with code 1003.

Can WebSocket handle both text and binary data?

WebSocket enables bidirectional, message-oriented streaming of text and binary data between client and server. It is the closest API to a raw network socket in the browser.

What type of data is used for WebSocket?

In the browser, we directly work only with text or binary frames. WebSocket . send() method can send either text or binary data.

When should you not use a WebSocket?

You might be using WebSockets incorrectly if: The connection is used only for a very small number of events, or a very small amount of time, and the client does not need to quickly react to the events. Your feature requires multiple WebSockets to be open to the same service at once.


1 Answers

Supporting binary data in WebSocket servers is pretty trivial (less work that UTF-8 actually). The real problem is supporting binary data types in the browser. It is being worked on, but as of yet there are no browser releases that can support sending and receiving binary types (typed arrays, blobs).

If you need to send binary data now before browsers add support, you can try my websockify python server and Javascript client library. It uses base64 encoding to transfer binary data over the wire. Instead of typed arrays/blobs, it uses arrays of numbers (0-255) to represent binary data on the Javascript side.

Some links:

  • Mozilla bug #666349
  • WebKit bug #65249 (parts about binary data support are all fixed now)
  • W3C WebSockets API
  • IETF HyBi WebSockets protocol v10
like image 143
kanaka Avatar answered Sep 19 '22 16:09

kanaka