Networking layer design decisions

Started by
1 comment, last by hplus0603 12 years, 3 months ago
Im working on a game project for quite a while now and now Ive finally come to the point where I need to design its networking layer. As always, the dreaded UDP or TCP question arises, and before I waste too much time due to wrong design decision, Id like to present my thoughts here and gather some feedback from you guys...

Up until now, I had a monolithic application, where the server was only a bundle of gamelogic classes, but for several different reasons, Im planning to make the game online only, with a central server in the web and downloadable clients.

I experimented already with a small network layer using UDP for testing in my LAN, but since package loss became apparent I have to decide now which way Ill go with networking in general.

Right now I think trying to make my own reliability layer with UDP is the way to go, but the reasons against that are equally important as the reasons in favor of it. The following listing is ordered by importance.

Pros UDP:
[indent=1]- The engine I wrote which is used by my game is more flexible and therefore better usable by future game projects
[indent=1]- With UDP, sending and listening is the same on client and server, which makes it easier to develop
[indent=1]- No separate threads for connected clients or accepting connections in the server
[indent=1]- I dont need to worry about message fragmentation
[indent=1]- I dont need to dump my network layer.. Its tiny, but at least its doing its job so far

Cons UDP:
[indent=1]- My current game is a turn based strat game, which is THE standard use case for TCP in gaming
[indent=1]- Reliability and ordering is provided, doing this myself in UDP might be a terrible amount of work

Do you think this is the right decision or did I misjudge some points here?

Using an already existing library (raknet or such) isnt really what I want to do, since I would like to write it myself (yeah, Im mad, I know..).
Advertisement

Using an already existing library (raknet or such) isnt really what I want to do, since I would like to write it myself (yeah, Im mad, I know..).

Hmm i would have suggested enet bc its tiny and provides everything needed. It builds the connection and you can choose if you want the packets to be reliable/in order/unordered/unreliable. But since you want to code everything yourself i would say take a look at the quake3 network layer. Its really basic, easy to implement and as well gives you reliable data. I actually implemented a quake3 network system with enet and sending unreliable-ordered packets which works great and gives good performance. I know this hides the really low level network stuff from ya but since you want to write a game and not a network lib i would really recommend that.

Enet: http://enet.bespin.org/
Quake3 network explained: http://trac.bookofho...uake3Networking (currently down??)
maybe this helps as well http://ra.is/unlagged/network.html
Most of your "pros" of UDP aren't really pros of UDP. You don't need a thread for managing TCP at all, for example.

In the end, which way you go depends entirely on what ends up working best for you. Personally, I find that TCP is easier to work with, and would use that where possible. If it eworks for World of Warcraft, it can't be all bad. (More FPS style games or simulations, though, and you'd want UDP)

Regarding "the engine is ready for whatever I do next" -- that's generally not a great reason to make a choice for the current game. It's hard enough to ship the current game -- you should make the right choice for that. IF you need another choice for the next game, then you can re-make that choice later, but making a choice for some future possible benefit that you have no way of proving or testing right now is not generally the smartest strategy.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement