Game dev
Saved & recent

UDP and TCP

Related terms: transport, reliable, unreliable, packet

The two ways to send data over the internet. TCP guarantees that everything arrives, in order. When one packet is lost, everything behind it waits for the resend, which the player feels as a freeze.

UDP makes no promises. Packets can arrive late, out of order or not at all, but nothing ever waits. Fast games use UDP, because an old position update is worthless anyway, and add their own reliability only for messages that must arrive.

Further reading
Glenn Fiedler: UDP vs. TCP
TCP network arrivals 1 2 3 4 1 2 3 buffered 4 3, 4 retry lost application delivery UDP network arrivals 1 2 3 4 1 2 4 — lost application delivery
Numbers mark parts of the TCP byte stream and individual UDP datagrams. The TCP application receives the contiguous bytes for 3 and 4 after retransmission. UDP delivers datagram 4 with a gap at 3.

View in the full Game dev collection