None None - 2 months ago 22
C# Question

Why do game developers avoid TCP and make UDP reliable in the application level?

Many game developers choose to a make UDP reliable in the application level. Isn't that what TCP is made for? I made an API that enables Client-Server communication using UDP and TCP packets. Should I add Reliable UDP to the list? And why? Is there a problem if I use TCP?

I just want to know if RUDP has any benefits over TCP, so that I can choose whether to add RUDP support or not.

Answer

If I'd directly say that UDP is faster, comparatively than TCP that it is used for such applications; you won't believe and accept. The developers, carrying on this, thus developed some reliability on UDP (called RUDP) to make it somewhat imitate TCP. Still, it doesn't implement TCP functionalities completely(in totality).

That's why I'd like to answer your question with reference to an article Reliable UDP (RUDP): The Next Big Streaming Protocol? :

TCP has a set of instructions that ensures that each packet of data gets to its recipient. It is comparable to recorded delivery in its most basic form. However, while it seems obvious at first that "making sure the message gets there" is paramount when sending something to someone else, there are a few extra considerations that must be noted. If a network link using TCP/IP notices that a packet has arrived out of sequence, then TCP stops the transmission, discards anything from the out-of-sequence packet forward, sends a "go back to where it went wrong" message, and starts the transmission again.

If you have all the time in the world, this is fine. So for transferring my salary information from my company to me, I frankly don't care if this takes a microsecond or an hour, I want it done right. TCP is fantastic for that.

In a video-centric service model, however, there is simply so much data that if a few packets don't make it over the link there are situations where I would rather skip those packets and carry on with the overall flow of the video than get every detail of the original source. Our brain can imagine the skipped bits of the video for us as long as it's not distracted by jerky audio and stop-motion video. In these circumstances, having an option to just send as much data from one end of the link to the other in a timely fashion, regardless of how much gets through accurately, is clearly desirable. It is for this type of application that UDP is optimal. If a packet seems not to have arrived, then the recipient waits a few moments to see if it does arrive -- potentially right up to the moment when the viewer needs to see that block of video -- and if the buffer gets to the point where the missing packet should be, then it simply carries on, and the application skips the point where the missing data is, carrying on to the next packet and maintaining the time base of the video. You may see a flicker or some artifacting, but the moment passes almost instantly and more than likely your brain will fill the gap.

If this error happens under TCP then it can take TCP upward of 3 seconds to renegotiate for the sequence to restart from the missing point, discarding all the subsequent data, which must be requeued to be sent again. Just one lost packet can cause an entire "window" of TCP data to be re-sent.


Many game developers choose to a make UDP reliable in the application level. Isn't that what TCP is made for?

If you can tolerate with the speed of how data is being processed at the both ends, it is OK.

But, in games, this is not OK. You have to pass video frames(and audio,etc.) many times per second an that too to many players(if multiplayer). It all needs much more speed, and faster data processing capability; instead of using the comparatively slower TCP. Even if some packets are dropped midway, it is OK for the application to move ON, as the brain too would move on to next rather than thinking about those jitters.

I made an API that enables Client-Server communication using UDP and TCP packets. Should I add Reliable UDP to the list? And why? Is there a problem if I use TCP?

That depends on how better you want to application to be responsive. I'd suggest you to add Reliable UDP to your list.

I've already mentioned the problems with the TCP.

I just want to know if RUDP has any benefits over TCP, so that I can choose whether to add RUDP support or not.

With low overhead, and higher speed, I'd bet for reliable UDP, than the bulky TCP - for developing such applications(gaming).

Comments