Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tcp Reliability versus Udp Burdens for serious, high-performance server

Speed, optimization, and scalability are the typical comparisons between the Udp and Tcp protocols. Tcp touts reliability with the disadvantage of a little extra overhead, but speed is good to excellent. Once a Tcp socket is instanced, keeping the socket open requires some overhead. But compared to the oft described burdens of Udp, which protocol actually has more overhead?. I've also heard that there are scalability issues with Tcp...yet the Internet (Web pages/servers) runs on Tcp - so what is it about Tcp that inhibits scalability?

Okay...so Udp doesn't require that overhead of keeping a connection open. But, it requires that you write extra methods to ensure all of the packet gets there, hopefully in the order that you want it received. If a packet isn't received in full, then you have to tell the client or server to resend. And you also have to keep some sort of message collection for partial packets, rebuild the partial messages, and check for a complete message before the message can finally be processed. Not to mention if the second part of a message never makes it, you have to either say resend the entire thing, or resend the part we are missing, or whatever.

Basically, my questions are:

  1. Why would I choose Udp over Tcp for a serious, high-performance server with the added "overhead" of message checking and manual ACK versus the "overhead" of a continuous stream?
  2. If Tcp is good enough for the likes of World of Warcraft, why isn't Tcp more widely accepted as the protocol to use for a game server?

Note: I am not opposed to implementing Udp options for a server. We are using C# on .Net 3.5 framework. So I would also be interested in the best practices for dealing with Udp burdens. I am also using the asynchronous methods at the socket level rather than using TcpListener, TcpClient, etc. etc.

like image 882
IAbstract Avatar asked Mar 01 '10 05:03

IAbstract


People also ask

Is TCP is more reliable than UDP?

Transmission control protocol (TCP) and user datagram protocol (UDP) are foundational pillars of the internet, enabling different types of data transmission from a network source to the destination. TCP is more reliable, while UDP prioritizes speed and efficiency.

Why TCP is reliable and UDP is unreliable?

TCP is Reliable as it provides reliability of delivery of packets to the receiver while UDP is Non-reliable and does not give information about the packets. TCP is Connection oriented it means connection is to be setup before data is sent that is done in form of 3-way handshake while UDP is Connectionless.

Why is UDP less reliable than TCP?

TCP is more reliable than UDP. UDP is faster for data sending than TCP. UDP makes error checking but no reporting but TCP makes checks for errors and reporting. TCP gives a guarantee that the order of data at receiving end is the same as on sending end while UDP has no such guarantee.

Does UDP provide reliability?

UDP uses a simple transmission model without implicit handshaking techniques for providing reliability and ordering of packets. Thus, UDP provides an unreliable service and datagrams may arrive out of order, appear duplicated, or go missing without notice.


1 Answers

Well, I would recommend reading up some more. There are plenty places to look at the pro's and con's of TCP vs. UDP and vice versa, here are a few:

  • What Are The Advantages Of Using TCP Over UDP?
  • When should I use UDP instead of TCP?
  • TCP and UDP
  • What are the advantages of UDP over TCP?

However, this link may interest you the most, as it is directly about networked game programming:

  • Gaffer on Games - UDP vs. TCP

If I were to quote something small:

The decision seems pretty clear then, TCP does everything we want and its super easy to use, while UDP is a huge pain in the ass and we have to code everything ourselves from scratch. So obviously we just use TCP right?

Wrong.

Using TCP is the worst possible mistake you can make when developing a networked game! To understand why, you need to see what TCP is actually doing above IP to make everything look so simple!

I still recommend doing your own research on the matter though, and make sure which of the protocols suits your needs at the end of the day. This being said, it does seem to be the case that majority of games use UDP for their data. Anything that updates the entire state continuously does not need the overhead of guaranteed packet delivery.

like image 71
Kyle Rosendo Avatar answered Sep 18 '22 15:09

Kyle Rosendo