开发者

WebSocket data compression

Does WebSocket provide support for da开发者_JAVA技巧ta compression to save bandwidth? What are the options available? One possible solution could be use of Bijson in place of Json.


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.


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


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 eamorr@172.16.1.218 -L 6999:172.16.1.218:3129

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜