Original Post
I've recently been spending a lot of time on programming the networking system for my latest game and I thought I would write a little summary of my experience so that others don't make the same mistakes I did. About four years ago I wrote my first proper game which was a 3D version of the classic snake game. I attempted to write the networking code using TCP/IP so that the game could be played head to head. It worked more or less but needless to say this is a BAD idea for action games such as this. I found that large lag spikes would occur because data that failed to get through the first time was holding up the whole thing prevent further communication from happening. A few years later while developing my next game I decided to go for UDP using the fairly low-level library "enet" (http://enet.cubik.org/) which basically adds a reliability layer on top of UDP. As a programmer you get to choose if packets are to be sent reliably or not. I found this worked much better and I didn't get any lag spikes. I was impressed with the robustness and quite happy with the final result. Recently, I started developing my most ambitions game yet. And this time I wanted to have the real deal. I.e. Master server so that players can easily locate and join servers running the game. NAT punchthrough to circumvent problems of hosting games behind a firewall. Auto-patching of the client to the latest version from the internet. That's when I came across RakNet which claims to provide a robust networking solution like enet as well as providing high level functionality I wanted for my game. My first impressions of RakNet were not good, the frontpage contains outdated information and the only download link I could find was to latest beta version "RakNet30Beta.zip". There were no links to a "stable" version. Usually I prefer to work with stable libraries but since I had no option I went with it. After having implemented the networking in my game and got the basics working I decided to give the client auto-patcher a spin. This is where I ran into real trouble. The system only transferred part of the files and then stopped midway through. I spent several days stripping things down trying to find the source of the problem. No luck, all I could determine was that the problem did not come from my own fault and was far deeper rooted than the auto-patcher code. There was a problem with sending large amounts of data at once, in theory RakNet should deal with splitting the packets up and sending them in sequence. However at some point packets just stopped being sent. I thought to myself, how is it possible that this problem could go unnoticed. After all the front page of the website lists a number of games in which the library has been used. I thought that perhaps the problem was introduced in the later versions of the library. So I managed to get a copy of RakNet v2 stable version from the source control system they use. Still no luck, the damn thing still stops while downloading. So I gave up on that while I returned back to programming the main networking code. Shortly after I noticed that I was getting highly variable pings even when tested over my local area network. I finally got so frustrated that I stripped RakNet out of my game and replaced it with enet. Fortunately I had placed all the networking code into a separate class and the process of switching library was not too lengthy but was nevertheless a pain in the ass. After switching back to enet, I got the low stable pings I came to expect from my previous game. So I guess what I'm trying to say here is think twice before using RakNet if you want to avoid headaches. It may take longer to implement things such as auto-patching, master server, nat punch through, etc. But at the end of the day, all those RakNet features are useless if you don't have a fast robust networking system. I did quite a bit of searching for information and comparisons on different UDP networking libraries but unfortunately I couldn't find much. So hopefully if you are reading this and can't decide what to use this will help you in making a decision. [Edited by - SpaceDude on May 2, 2007 11:29:07 AM]