Search code examples
c#tcpudpmonogamemultiplayer

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?


Solution

  • 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.