My experience with networking libraries

Started by
7 comments, last by SpaceDude 16 years, 11 months ago
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]
Advertisement
If you're basing your "don't use Raknet" on the autopatcher feature alone then that's pretty stupid. Plenty of people have used it for various projects with fine results. Some would argue that an auto patcher doesn't belong in a networking library anyhow.

It'd be faster and more efficient to simply have the client pull patches or the newest file from an http or ftp server that is seperate from the game server, something very trivial to implement.
I agree that the fact the auto-patcher is broken alone is not a deal breaker. But as I said, the problem is far deeper than that. I don't want this to turn into an argument about what is the best way to patch a game but your statements about using the HTTP or FTP protocols are incorrect. And if indeed the high level features of RakNet are of no concern, there is no reason to use RakNet over enet.
Added to FAQ.
enum Bool { True, False, FileNotFound };
What is incorrect? The fact that it's easier? The fact that its the preferred method of most MMOs?

Why would someone go through the trouble of sending large files through the games networking layer when they can use a protocol optimized for file transfers? Especially considering that the client usually doesn't download patches from the actual game server. That's why they have patch servers.

There's plenty of other higher level niceties in Raknet without an autopatcher. Why you chose to trash the entire thing due to problems you've had with the most insignificant feature is a mystery.
Well, it's their fault for not notifying people about the autopatcher not working, it doesn't actually give you a good image on how they do things. First impression counts. If they don't want people judging by that function, then they shouldn't have it in there.
AutoPatcher is a unique feature to RakNet, not used by many other libraries I have seen. Of course one would want to judge by it, especially if you wanted to use the library for that purpose.

One problem reveals more problems...

Programming=Creating,Your fantasy is the only limit!

One very good thing about RakNet is that the developer is very active on his forum and happy to help you with problems you're having. I asked about a feature I wanted, and he posted a small patch on the forum that would change RakNet to that the next day. Notably on the forums recently you may have missed this recent announcement:

New 3.0 Build (04/24/07)
Fixes the reported problem with the autopatcher stopping.
Download from the front page.


Yay for responsiveness!
Quote:Why you chose to trash the entire thing due to problems you've had with the most insignificant feature is a mystery.


Actually, it seems to me, from actually reading the well-thought-out write-up, that the main problem was poor jitter performance, which the author did not get when using Enet on the same network.

Thus, if there is jitter with RakNet, and no jitter with Enet, then RakNet might have some more engineering to do. Jitter is bad, and is not something that I would want to get from my networking library (what I get from the internet is bad enough :-)
enum Bool { True, False, FileNotFound };
Quote:Original post by DrEvil
What is incorrect? The fact that it's easier? The fact that its the preferred method of most MMOs?

Why would someone go through the trouble of sending large files through the games networking layer when they can use a protocol optimized for file transfers? Especially considering that the client usually doesn't download patches from the actual game server. That's why they have patch servers.

There's plenty of other higher level niceties in Raknet without an autopatcher. Why you chose to trash the entire thing due to problems you've had with the most insignificant feature is a mystery.


- The autopatcher is intended to be hosted on a "master" server not on the game server. The main reason being that allowing game servers to send files to the client which may included executables is a huge security risk. The reason not to use simple file transfer protocols such as HTTP or FTP is that it is more efficient to only send the parts of the files that have been updated rather than sending the whole file again. This is what the autopatcher is designed for.

- I'm not trying to trash the whole RakNet library based on the autopatcher alone, problems are deeper than that. I am simply advising caution before jumping in and writing a whole bunch of code that depends on it. I have no intention of doing a thorough check of the RakNet system to find out which parts are broken and which are not. This should be the job of the RakNet author, which doesn't seem to be have done as well as it should have been.

Quote:Original post by Ozymandias43
One very good thing about RakNet is that the developer is very active on his forum and happy to help you with problems you're having. I asked about a feature I wanted, and he posted a small patch on the forum that would change RakNet to that the next day. Notably on the forums recently you may have missed this recent announcement:

New 3.0 Build (04/24/07)
Fixes the reported problem with the autopatcher stopping.
Download from the front page.


I have not missed this thread, the forum was the first place I went when I encountered problems. The so-called "fix" does not fix the problem at all. I spent about a week on the forum discussing the issue but got nowhere, the only response I got from the Author was "I don't see the problem but I will look at it more in the near future.". I am not alone, another user reported the same problem.

This topic is closed to new replies.

Advertisement