javascript Websockets 和二进制数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6869926/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Websockets and binary data
提问by Dmitrii Sorin
As far as i know websockets support binary data transfer. Binary support bug is fixed.
据我所知,websockets 支持二进制数据传输。二进制支持错误已修复。
So, are there any websocket servers which support binary data transfer? Socket.io seems to miss this opportunity. Maybe there are some others?
那么,是否有任何支持二进制数据传输的 websocket 服务器?Socket.io 似乎错过了这个机会。也许还有其他一些?
回答by kanaka
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).
在 WebSocket 服务器中支持二进制数据非常简单(实际上比 UTF-8 少得多)。真正的问题是在浏览器中支持二进制数据类型。它正在开发中,但目前还没有浏览器版本可以支持发送和接收二进制类型(类型数组、blob)。
If you need to send binary data now before browsers add support, you can try my websockifypython 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.
如果你现在需要在浏览器添加支持之前发送二进制数据,你可以试试我的websockifypython 服务器和 Javascript 客户端库。它使用 base64 编码通过网络传输二进制数据。它不是类型化数组/blob,而是使用数字数组 (0-255) 来表示 Javascript 端的二进制数据。
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
- Mozilla 错误 #666349
- WebKit 错误 #65249(关于二进制数据支持的部分现已全部修复)
- W3C WebSockets API
- IETF HyBi WebSockets 协议 v10
回答by oberstet
Here is a comparison of WebSockets implementations (browsers, client, servers) that has a feature row for "binary messages":
这是具有“二进制消息”功能行的 WebSockets 实现(浏览器、客户端、服务器)的比较:
http://en.wikipedia.org/wiki/Comparison_of_WebSocket_implementations
http://en.wikipedia.org/wiki/Comparison_of_WebSocket_implementations
Currently (09/16/2011), the browsers supporting binary WS messages are:
目前 (09/16/2011),支持二进制 WS 消息的浏览器有:
- Chrome 15 or higher
- IE10 (part of Windows 8 developer preview)
- Firefox 11 or higher
- Chrome 15 或更高版本
- IE10(Windows 8 开发者预览版的一部分)
- 火狐 11 或更高版本
For detailed test reports and browser comparison, see:
详细的测试报告和浏览器对比见: