WebSocket数据压缩
WebSocket 是否提供数据压缩支持以节省带宽? 有哪些可用选项? 一种可能的解决方案是使用 Bijson 代替 Json。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
WebSocket 是否提供数据压缩支持以节省带宽? 有哪些可用选项? 一种可能的解决方案是使用 Bijson 代替 Json。
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
当前的 WebSockets 协议草案不包含压缩扩展。以前有一种:deflate-stream,它的工作原理是压缩整个 WS 流。其有效性是有限的,因为 WS 引入了客户端到服务器的帧掩码,每帧都会更改掩码,因此 deflate 将无法保留有效的压缩字典。
有一个基于帧的压缩提案草案可以解决这个问题,因为压缩字典是在屏蔽之前为有效负载维护的。
The current WebSockets protocol draft does not contain a compression extension. There was one formerly: deflate-stream, which works by compressing the whole WS stream. The effectiveness of that is limited, since WS introduced client-to-server frame masking, with mask changed per frame, and by that, deflate would not be able to keep a effective compression dictionary.
There is a draft proposal for frame-based compression which works around this, since the compression dictionary is maintained for the payload before masking.
Websockets 节省带宽的第一种方法是为多个(双向)消息保持开放连接。只要需要,连接就可以保持打开状态。这意味着不需要像旧的 http 方法那样为每个事务协商新的连接。消息本身具有标头信息,用于指定传入消息是文本还是二进制,以及“有效负载”的长度。
您可以让您的服务以您想要的任何方式解释消息。具体的压缩相关数据可以通过扩展来表达:参见标准第9节:https://datatracker.ietf.org/doc/html/draft-ietf-hybi-thewebsocketprotocol-15#section-9
标准组织已经制定了压缩扩展的工作草案:https://datatracker.ietf.org/doc/html/draft-tyoshino-hybi-websocket-perframe-deflate-00
The first way that Websockets save bandwidth is by leaving the connection open for multiple (bi-directional) messages. The connection can remain open as long as it's needed. This means that a new connection does not need to be negotiated for every transaction like the old http approach. The messages themselves have header information that specifies whether the incoming message is text or binary, and how long the "payload" is.
You can let your service interpret the messages in whatever way you want. Specific compression related data can be expressed through extensions: See section 9 of the standard: https://datatracker.ietf.org/doc/html/draft-ietf-hybi-thewebsocketprotocol-15#section-9
The standards organization has produced a working draft for compression extension: https://datatracker.ietf.org/doc/html/draft-tyoshino-hybi-websocket-perframe-deflate-00
WebSocket 规范允许扩展,例如 deflate-stream。但是,客户端和服务器可能支持也可能不支持。
您可能想要使用基于 javascript 的 Zip 或其他压缩算法。
WebSocket specs allow extensions, such as deflate-stream. However, it may or may not be supported by the client and server.
You may want to use javascript-based Zip or other compression algorithms.
您可以通过关闭加密并将压缩集设置为最大的 ssh 连接来隧道传输所有内容吗?
例如:
ssh -N -g -f -C -o CompressionLevel=9 -o Cipher=none [电子邮件受保护] -L 6999:172.16.1.218:3129
You could tunnel everything through an ssh connection with encryption turned off and compression set to maximum?
e.g.:
ssh -N -g -f -C -o CompressionLevel=9 -o Cipher=none [email protected] -L 6999:172.16.1.218:3129