11

Does WebSocket provide support for data compression to save bandwidth? What are the options available? One possible solution could be use of Bijson in place of Json.

4 Answers 4

4

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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

Comments

1

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.

Comments

-3

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.