"It depends".
I would start with the main candidates: LZMA ("7-zip"), deflate (direct, zlib: deflate + small wrapper, gzip: deflate + a little big wrapper, zip: deflate + even more wrapper), bzip2 (I doubt that it would be so good here works best with a relative large window), perhaps even one of the other LZ * branches, such as LZS, which have RFCs for compressing IP traffic , but ...
... do some evidence-based analysis and compression / throughput using several different approaches. Java has a GZIPOutputStream ("deflate in gzip wrapper") and DeflaterOutputStream ("plain deflate", it is recommended to use gzip or zip "wrappers"), and there are LZMA Java implementations (you just need a compressor, not a container), so all this should be trivial for layout.
If there is regularity between the packets, perhaps this could be used — for example, building cache mappings, Huffman tables, or just modifying the “windows” of one of the other algorithms, but the probability of packet loss and “compressibility” should probably be taken into account. Descent along this route adds much greater complexity. More ideas to help the compressor can be found in SO: How to find a good / optimal dictionary for zlib 'setDictionary' when processing a given dataset? .
In addition, the protocol should have a simple “return” of zero compression, because some [especially small random] data may be practically incompressible or may “compress” to a larger size (zlib actually has this protector, but also has “service wrapper data ", so it will be better encoded separately for very small data). The overhead of the wrapper for compressed data — for example, gzip or zip — should also be taken into account for such small sizes. This is especially important for considering string data of less than ~ 100 characters.
Happy coding.
Another thing to keep in mind is the encoding used to translate characters into the output stream. First I have to start with UTF-8, but that may not always be perfect.
See SO: The best compression algorithm for short text strings that SMAZ offers, but I don’t know how this algorithm will go unicode / binary.
Also consider that not all deflate (or other format) versions are created equal. I don't refer to standard Java deflation compared to third parties (say JZlib ) in terms of performance for small data, but consider Small Payload Compression [.NET] , which shows pretty negative numbers for the "same compression" format. The article is also beautiful:
... it is usually most beneficial to compress it anyway and determine which payload (compressed or uncompressed) is the smallest and includes a small token to indicate whether decompression is required.
My final conclusion: always check with real data and measure the benefits, or you may be a little surprised at the end!
Happy coding. Actually this time.