Deflate extension

vtortola edited this page May 5, 2014 · 10 revisions

The Deflate compression extension is a "per message" extension that follows the Compression Extensions for WebSocket draft-ietf-hybi-permessage-compression-17.

This extension does not support context takeover, and so it is indicated in the WebSocket negotiation.

  • What does that mean? Messages will be compressed independently, the compression dictionary will not be shared across messages. That yields a lower compression rate.

  • Why is not supported? The reason is that there is no deflate compression tool in the .NET framework that allows to compress arbitrary buffers. DeflateStream can compress/uncompress a full stream, but not just part of it.

  • Do I have to do anything? No. The extension will let the client know that the context takeover is not supported during the websocket negotiation. It should work just fine.

  • Should I use it? If you are sending big text payloads (JSON, text, etc...) probably yes. If you are sending small delta messages (small updates), maybe not. You should try and see if it yields any benefit for your particular case.

It is on the vtortola.WebSockets.Deflate.dll assembly, and it is called WebSocketDeflateExtension. It needs to be added to the WebSocketListener before start:

var rfc6455 = new vtortola.WebSockets.Rfc6455.WebSocketFactoryRfc6455(server);
rfc6455.MessageExtensions.RegisterExtension(new WebSocketDeflateExtension());
server.Standards.RegisterStandard(rfc6455);