Johnaudi Hey there, I'm making a 2D hybrid-MMO, been searching recently and found that TCP is more realiable, but UDP is faster transmission with less packet headers (less space taken). What do you think is better for making this game? I had set up a TCP server and client first, but then I moved to UDP. Any ideas? Thanks in advance.
Tarek TCP stands for “transmission control protocol” This connection is reliable and ordered, meaning that all data you send is guaranteed to arrive at the other side in the same order that you wrote it. Its also a stream of data, meaning that TCP takes care of splitting up your data into packets and sending those across the network for you. (...) UDP is an unreliable protocol. In practice, most packets that are sent will get through, but you’ll usually have around 1-5% packet loss, and occasionally you’ll get periods where no packets get through at all (remember that there are lots of computers between you and your destination where things can go wrong…) Source: http://gafferongames.com/networking-for-game-programmers/udp-vs-tcp/
rolf One of the key differences between the two is that TCP is aware of tge sequence of packets. UDP is not, sou you might have packets arriving in a different order, and some not arriving at all. Ask yourself how important it is. Generally, for non time-critical applications, TCP is better, for the added reliability.
ILIA_93 Use UDP for real-time applications ( Video calls, VoIP, Gaming, ...), and TCP for everything else.
Joe Tarek's answer does a great job at explaining the most important thing to consider: UDP is a pain in the ass to use. But sometimes you really need it. You should assume by default that everything should be done over TCP. It's easier, safer, and will avoid a lot of headaches. However, if you're designing a game played over the network that needs precise timing (if your players are going to be affected by a network lag), you want to stream this feed over UDP. If, on the other hand, you're creating a turn-based game where each player has multiple seconds to take a decision, you can ditch UDP altogether. NB: When I say you should stream the in-game feed over UDP, I don't mean you should drop TCP completely. Menus, character selection, settings and customization, in-game chat, ... are just examples of modules you would want to stream over TCP in any case.
Johnaudi This is great advice, I'll be using both then. I'll try to create a server that will multi-thread UDP and TCP, and sub-thread each client within. And to receive the data we'll be using a TCP client on a thread, a UDP client on another, and the game on the main one. Sounds good?
jsaade Hi, you need to carefully handle lost & out of sync packets when using UDP not to mention NAT punch through assuming it is going to be using the internet. Gaffer on games has more tutorials for physics based simulations where dropped packets have a lot of significance (like first person shooters). MMOs are usually done using tcp, UDP is more for first person shooters but with those there is a lot of issues (client side prediction, packets correction, etc.). From what I know world of warcraft uses TCP for their data communications. When I say usually it is because in MMO you can get away with a lot of synching stuff as the server sends a correction packet every few frames. If this is your first network game, use a library like RakNet (which is now opensource thanks to OcculusVR). Also check gamedev.net forums there is a section for network programming you will get a lot of help there. Btw, this should be moved to programming.
rolf jsaade wroteHi, you need to carefully handle lost & out of sync packets when using UDP not to mention NAT punch through assuming it is going to be using the internet. Oh yea, that's another issue. NAT traversal with UDP is much more tricky, if possible at all.