Which one would you trust with this?
Four apps, one rough line that loses about one packet in five. Pick UDP or TCP for each app, send twenty packets and see whether the app survives.
You
Them
arrivedarrived late or sent againnever arrivednot here yet
Pick UDP or TCP, then send.
Each mission has one protocol that suits it. Try the wrong one once to see why.
All four passed
- Use UDP when a late packet is worthless: video calls, games, live voice. Losing a packet is better than waiting for it.
- Use TCP when every byte must arrive in order: files, photos, web pages, payments. It pays with a handshake, 12 more header bytes per packet, and waiting.
- The cost of TCP’s promise is head-of-line blocking: one lost packet holds back everything behind it until it is sent again.
How this works: one tick is one step of time and a packet takes 3 to 5 ticks to cross. UDP has an 8-byte header and sends one packet a tick. TCP has a 20-byte header, does a three-packet handshake, keeps up to 8 packets unacknowledged and resends any whose acknowledgement does not come back in 9 ticks. To keep it simple, the handshake and the acknowledgements are never lost, and acknowledgements are per packet, like TCP with selective acknowledgements. “Different luck” changes which packets the line loses.