Websockets and binary data
Solution 1
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
Solution 2
Here is a comparison of WebSockets implementations (browsers, client, servers) that has a feature row for "binary messages":
http://en.wikipedia.org/wiki/Comparison_of_WebSocket_implementations
Currently (09/16/2011), the browsers supporting binary WS messages are:
- Chrome 15 or higher
- IE10 (part of Windows 8 developer preview)
- Firefox 11 or higher
For detailed test reports and browser comparison, see:
Dmitrii Sorin
Updated on June 19, 2022Comments
-
Dmitrii Sorin almost 2 years
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?
-
Dmitrii Sorin over 12 yearsso none of modern browsers support binary messaging :(
-
oberstet over 12 yearsFor Firefox/Chrome I would guess it's a question of months till they support binaries.
-
ebidel over 12 yearsChromium just landed support for binary messaging: code.google.com/p/chromium/issues/detail?id=93652
-
oberstet over 12 yearsyep, it's there. I have updated WebSockets test suite reports including Chrome and different versions of Firefox to reflect that: tavendo.de/autobahn/testsuite/report/clients
-
kanaka over 12 yearsBinary support is in recent Chrome releases. There is finally action on the Mozilla front and I expect the next Aurora (alpha) release of Mozilla will have support too. I suspect that IE 10 also has support but I have not explored that directly.
-
josesuero almost 12 years@kanaka do you know if there's any way to query the browser for binary support? It looks like FF10 , which doesn't support binary frames, just silently discards the "bad" frames.
-
kanaka almost 12 years@jalf, unfortunatly, there is no clean and easy way. The only object detection method that I know of is to instantiate a fake WebSocket object and then see if it has the binaryType attribute:
ws = new WebSocket("ws://localhost:12345"); if ("binaryType" in ws) { .... };
I complained about this before the initial support shipped in Chrome but got no traction to get it fixed.