Since I’ve been developing online games since 1991, many folks have asked me to recommend a 3rd-party network library for their game project.
Unfortunately, I can’t! At least I can’t recommend one from personal experience because the projects I’ve worked on — Warcraft, Diablo, Starcraft, battle.net and Guild Wars – were all built on proprietary, “from the ground up” network code I developed or co-developed.
But I’ve been meaning to do some research into 3rd-party network libraries so I don’t have to write something from scratch next time; it just takes too long. The core networking libraries I wrote for Guild Wars comprise about 50K lines of code and took several years to fully stabilize because of esoteric issues. To give you a brief idea of some of the scary bits:
- Setting TCP window size: enabling high throughput over long-distance connections without exposing servers to distributed denial-of-service (DDoS) attacks from clients connected to the same server.
- Message buffering: don’t drop a connection just because the other side stalled, but be careful not to allow DDoS attacks.
- Socket shutdown issues: close sockets “nicely” to avoid disconnect delay but don’t expose servers to DDoS attacks.
- Rate-limiting connections & throughput: ensure that servers can’t be abused by DDoS attacks – are you noticing a pattern here?!?
It is difficult to select a network library because there are so many parameters. Are you looking for a reliable message-pusher? Should it use TCP, UDP or both? Do you want object synchronization? Should object synchronization include client-side prediction? Do you want only client-to-server, or do you also need to handle server-to-server communications too? Cryptography? Network firewall traversal (aka UDP hole-punching)?
I’m going to start by eliminating libraries that don’t have a cross-platform story; let’s choose something that works for PC, console and mobile. While game projects don’t need to run on all of them, it is desirable for the programming team to be able to switch to different platforms without having to relearn everything.
Further, using a high-level API is a good choice for most game teams. Sending packets isn’t hard; sending reliable, compressed, scalable, encrypted, low-latency object-synchronization messages is hard. Let someone else do the work!
These high-level, cross-platform network libraries all look like they’re appropriate for game development:
Here are some other high-level libraries I looked at but don’t think are appropriate:
- Zoidcom – no pricing available on the site, which is a hassle up front.
- Torque Network Library (TNL) – no longer supported.
- TNL2 – also appears dead; GPL license prevents use in commercial game clients.
- ENet – lacking high-level documentation.
- ACE – looks dauntingly complex.
And here are some lower-level or more purpose-specific libraries:
- ZeroMQ – great for server-to-server but I wouldn’t use it for client->server: not robust against hacking.
- Boost ASIO – solid and complete, but (flame) using boost is a religious issue for some because it is especially hard-to-read C++ code, and can dramatically increase build-time (/flame).
- LibEvent – doesn’t support Windows well (only uses select, not IOCP).
- LibEv – doesn’t support Windows
- Google Protocol Buffers
- Apache Thrift
So that’s a start on the choosing anyway; I hope that helps reduce the scope of research required to get you started on your next game. Now can I join your beta?