Using zlib to compress traffic

Greetings all,

Im writing a small text based mmorpg and its going pretty good. Luckily im not stuck at the moment but I was told something a while ago and am now contemplating using it within the game. A friend suggested I should use zlib to compress my tcp packets both from the server and the clients and simply uncompress them each end as it could increase performance.

Heres my question.. Has anyone else tried this method to speed up traffic using tcp? I need to try and figure out if there will be any performance gain from having to compress and un-compress the other end rather than just sending data as normal. It might be a bit of an overkill aswell for a game which maybe only 20 people will be playing at once. I dont have any encryption at the moment with my data I simply sending ID numbers along with a number of different parameters. My data packets are not huge aswell they are in fact quite small. Perhaps the max size will be the odd packet of 1-2kb.

If anyone has any thoughts or experience in this matter I would appreciate hearing them.

Since the huge bulk of the overhead is actually sending a message, whether you send 20 bytes uncompressed or 10 bytes compressed isn't really going to make much difference.

You might benefit on the server->client traffic since this is likely to be a larger message (containing what up to 20 people just did), rather than the client->server message which just contains what you did.

So long as you've made a decent job of wrapping up the network interface, you can add compression and or encryption whenever you like. Like for example when you've had chance to test it in a proper real-world test environment. You could otherwise find yourself doing a whole lot of work for no real benefit.