Compressing TCP (and reliable UDP) streams is one of the things that often comes up in discussion with clients and I’ve helped several people implement stream compression using the TCP stream filtering API that’s part of The Server Framework. The filtering API is also used to provide SSL security over a stream and for things like asynchronous read timeouts, read sequencing, flow control and automatic reconnects. It’s a flexible API and the fact that it’s pluggable means that you can pick and choose from the various filters that form part of the framework and add whichever combination you fancy.
I’m just finishing work on a filter that applies compression to the stream. Whilst it’s always been pretty straight forward to help clients write their own it’s always useful to fold good ideas into the framework so everyone can take advantage of them. The compressing filter takes a pluggable compressor and at present I have a compressor that uses ZLib for the compression.
As with the SSL filters you don’t need to adjust your business logic code at all to take advantage of this functionality. Simply push the compressing filter onto your stream and you’re done. Inbound data is uncompressed before you see it and outbound data is compressed once you write it to the socket.
This new filter will be available in release 6.2 of The Server Framework which currently doesn’t have a release date but which shouldn’t be expected before early 2010.