Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebSocket data compression

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.

like image 616
abhihere Avatar asked Sep 21 '11 08:09

abhihere


People also ask

Does WebSocket support compression?

By default, websockets enables compression with conservative settings that optimize memory usage at the cost of a slightly worse compression rate: Window Bits = 12 and Memory Level = 5.

Are WebSockets vulnerable?

Some WebSockets security vulnerabilities arise when an attacker makes a cross-domain WebSocket connection from a web site that the attacker controls. This is known as a cross-site WebSocket hijacking attack, and it involves exploiting a cross-site request forgery (CSRF) vulnerability on a WebSocket handshake.

Is WebSocket slower than HTTP?

Simple RESTful application uses HTTP protocol which is stateless. All the frequently updated applications used WebSocket because it is faster than HTTP Connection.

Can WebSockets send binary data?

Data Types and ExtensionsWebSockets support sending binary messages, too. To send binary data, one can use either Blob or ArrayBuffer object. Instead of calling the send method with string, you can simply pass an ArrayBuffer or a Blob .


2 Answers

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

like image 120
Roger F. Gay Avatar answered Sep 21 '22 09:09

Roger F. Gay


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.

like image 24
oberstet Avatar answered Sep 20 '22 09:09

oberstet