python socket发送二进制数据的格式,websocket用于二进制数据传输&解码

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.

解决方案

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值