websocket用于二进制数据传输&解码 [英] websocket for binary transfer of data & decode

查看:2742
本文介绍了websocket用于二进制数据传输&解码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读规范和许多关于websockets使用的例子。几乎所有人都使用websockets讨论UTF-8或ascii消息传输。

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.

最新的Hybi websocket规范要求支持二进制传输。 hybi规范中的REQ 6

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

另外,我在某处看到chrome支持hybi。但最新版Chrome 7.0仅在pywebsocket中选择 draft-hixie 时有效配置。

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

是否有任何浏览器支持hybi规范?即使它是dev,也没关系。

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

推荐答案

在非UTF-8(即二进制)编码之前可能还需要一段时间WebSockets支持。

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

我建议在客户端和服务器上使用base64编码/解码。所有支持WebSockets的浏览器都有window.atob(base64 decode)和window.btoa(base64编码)。你可能编写WebSockets服务器的大多数语言都有base64库(即python中的base64模块)。

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).

如果你想传输二进制数据,你可能会对wsproxy感兴趣使用 noVNC ,这是一个基于Web的VNC客户端。 wsproxy(有一个C和python版本)是一个通用TCP套接字代理的WebSockets。它base64对来自浏览器的所有流量进行编码/解码。您可以使用它从支持WebSockets的浏览器连接到任何类型的TCP端口。

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.

注意,noVNC具有base64编码/解码的Javascript实现,因为信不信由你,Javascript版本比atob / btoa略快。

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

免责声明:我创建了noVNC。

Disclaimer: I created noVNC.

这篇关于websocket用于二进制数据传输&解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆