Game Development – TCP or UDP for Multiplayer Games?

game developmentnetworkingtcp

This is a question I see a lot. Most people say UDP is always better for real-time games than TCP. My understanding is that TCP tries to re-send packets over and over til the other side gets them whereas UDP doesn't care.

Most of the things I've read is that UDP is a must for any realtime game and TCP is terrible. But the thing is, most people seem to implement some form of TCP on top of UDP anyways. And I've also heard that the difference between the two is negligible given that we're not in the 80s anymore and the internet is now pretty fast and reliable.

Is my general understanding here wrong? Can someone clear this up for me?

Best Answer

Depends on if you're talking about peer-to-peer, client/server with the users running the server, or client/server with a data center running the server. Only in the latter-most case is the internet really fast and reliable. Your users' computers are not guaranteed to be fast, and certainly won't be reliable.

UDP allows you greater control over the sort of TCP-like implementation you're making. It gives you greater flexibility to execute packets out of order, discard packets that you consider unnecessary while retrying packets you consider important, that sort of thing. But this should only be done if needed and if you have the necessary expertise.

If you can do without that flexibility, TCP works well enough and saves you a whole lot of time. Even professional studios (like one I worked at) use TCP if they don't absolutely need UDP, and they have people dedicated to network programming.

Related Topic