UDP vs TCP – a follow up

by Christoffer Lernö

“You make it sound like we should always use UDP”

UDP isn’t a panacea. TCP is fine if latency isn’t critical – so if your game doesn’t need to keep latency consistently below 500 ms then by all means, try TCP first. The problem is with the commonly repeated advice claiming TCP is sufficient for everything short of FPS games. That advice is clearly wrong.

 “Why aren’t you mentioning head-of-line blocking?”

Head-of-line blocking is fundamental to any reliable, ordered protocol. I wanted to focus on the fact that TCP always assumes packet loss is due to bandwidth limits, which is why it is so ineffectual for packet loss on wifi or similar unreliable connections.

 “Better that people cut their teeth on TCP and finish their projects”

UDP is definitely more difficult do get right, and even if you use a library like ENet it’s important to know each has their own reliability algorithm which may or may not be suitable. – On the other hand, it’s important to clearly state that TCP has very fluctuating latency, and can render a low latency game unplayable. It’s important to know that such issues in many cases may be mitigated by converting to UDP.

A few links for further reading

Advertisements