kitsune4295
kitsune4295

Reputation: 89

Should I use TCP or UDP for the networking protocol for an MMORPG?

I am developing a MMORPG using C# and Monogame. Right now, I am working on developing the network protocol for it. I should note that I am a CCNA so I do have a pretty solid understanding on how both protocols work. However, I only have programmed single player games in the past. However I am a little stuck in trying to figure out which protocol I should use. I initially started my implementation using UDP, and have successfully sent single packets over my local network, but am worried that UDP may falter once I start adding more and more clients. Considering this is a connection for gaming, I initially came to the conclusion that I needed a connection that is fast, with low latency. But soon realized that some of the Packets I need to send can start to measure many KB in size, such as when a client enters a new area on the map, or a client trying to connect needs to update its local texture cache.

My question goes out to those who are experienced in making multiplayer games: Even with TCP's larger overhead, is it worth using it, or adjusting your game's protocol for reliability over UDP?

Upvotes: 2

Views: 11743

Answers (2)

Edward De Jong
Edward De Jong

Reputation: 181

TCP is convenient, but you pay for that simplicity in overhead. Every TCP packet is going to send an ACK packet saying "thank you" and telling the sender they got that segment #. These ACK packets, in the case of a big download, represent a lot of traffic. Remember that the internet on the main loses only around 1 out of 1000 packets, so verifying the transmission of each packet individually is mostly wasted information. Most of the cleverest games use UDP, and tightly pack the sent packet, using the most bit-twiddly tricks there are. Have a number that only goes 1..10?, then you use 4 bits only.

They also combine data from multiple packets into one packet so that they get max throughput. It is the # of packets per second that is really the limiting factor, and as long as you keep the packet size under the max for a non-split packet (which is not exactly 1500 but slightly less, and a tricky thing to determine) you can squeeze the most out of the transport hardware. For casual games with smaller users bases, it might not matter, but these massive multiplayer games have some of the biggest user bases in the whole world, and when you get to large numbers of users, wasteful transport mechanisms will require expensive server farms.

With enough good old fashioned bit twiddling, you can squeeze down the info you transport, and support massive numbers of users, but many people just want to move data from point A to B and not think about it much, which is why TCP is around. I particularly don't like how long TCP takes to recognize things have gone south, and am of the old-fashioned mentality that you should have total control of the process, and UDP is incredibly simple.

Another thing i like about UDP is that you can tell when the connection has gone crappy, and can warn the user. TCP conceals the problems from you to a great extent, and using UDP means you can inform the user that their play is being degraded. It is much nicer to the user to let them know their internet connection is lousy than having them think your game is lousy.

TCP has many compromises in it. It was very cleverly designed to handle flow control (kinda), and error correction, but for most games it is very inefficient. You would be shocked at how few people in the game industry know the network guts well; it is a small group of people who build the networking modules for many games, because it is really is a tricky sub-area. Unfortunately when you go to the web platform all you have is HTTP, which isn't even full TCP, and UDP is banned for security reasons.

Upvotes: 3

Edge Developers
Edge Developers

Reputation: 529

I know that several games will actually use both TCP and UDP protocol.

I know you are not using Unity, but here is a link that discusses TCP/UDP protocol for multiplayer use in games http://forum.unity3d.com/threads/should-we-use-udp-or-tcp.257217/

I also found several other resources:

http://ael.gatech.edu/cs4455f13/files/2013/08/Networking_Multiplayer.pdf

http://gafferongames.com/networking-for-game-programmers/udp-vs-tcp/

http://www.gamedev.net/topic/665565-game-master-server-udp-tcp-or-both/

After reading through these links, they explain the concepts very thoroughly and should be able to help you make a decision based on your game play style. The link to gafferongames looks to be the most helpful -it explains these things with a lot of depth. I would suggest at least reading the section named:

Wait? Why can’t I use both UDP and TCP?

A quote from the last link shows that it greatly depends from project to project:

It depends on the situation. When it comes to server-to-server communication there is no 'usual' method. You could go with anything from a custom ultra light UDP protocol, or your own more complex protocols that you design and build, ranging through standardized systems like JDBC/ODBC, or even REST based calls. The knowledge of what to pick in individual scenarios is a reason network infrastructure engineers are paid so well. :-)

It ultimately depends on what you are doing, and what you want out of the application. Some people disagree with using both because it can cause issues. The best thing is to read through a these sites and decide based on the pros and cons of using each.

EDIT: I found a few more sites that discuss this more specifically for MMORPG games:

http://www.gamedev.net/topic/319003-mmorpg-and-the-ol-udp-vs-tcp/

https://gamedev.stackexchange.com/questions/431/is-the-tcp-protocol-good-enough-for-real-time-multiplayer-games

One of these sites suggest using only TCP protocol for MMORPG games, the other suggests only using TCP for non-real time games. The second link discusses the pros and cons to using each and the overhead associated.

This is the best suggestion I have found, and essentially my answer for your question summed up:

Doing two may be benificial, but I'd suggest working with TCP now, leaving in hooks for UDP later. I think it would be more benificial to get the project up and running then worrying about latancy issues this early. As pointed out in that Quake 3 article I linked, doing both TCP and UDP at the same time introduces intresting and very hard to track bugs.

Upvotes: 5

Related Questions