Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
TCP vs UDP  ›  Lesson

Reliable vs Unreliable, Ordered vs Unordered

Reliable vs Unreliable 12 minTCP makes everything reliable and ordered while UDP makes nothing so, and a game server picks per message by asking whether a newer message replaces it and whether its order matters.

Reliable vs Unreliable, Ordered vs Unordered

You have now seen both extremes. TCP makes every byte reliable and ordered, whether you need that or not. Plain UDP makes nothing reliable and nothing ordered. A game server lives in between, and it chooses message by message.

The rule

If a newer message replaces it, send it unreliable; if not, reliable.

Two questions decide every message:

  • Reliable? Must it arrive? It must if nothing sent later makes it pointless.
  • Ordered? Must it be applied in the order it was sent, relative to other messages? Chat lines must be; independent events may not care.

The answers map onto the channels most game networking libraries offer:

Manja Arena message Replaced by a newer one? Channel
Kite positions (snapshot) Yes, next tick Unreliable, sequenced: keep only the newest
Player inputs No, but each goes stale within a few ticks Unreliable, with the last few repeated in every packet
"Kite 9 cut by kite 4" No Reliable
Chat line No, and order matters Reliable, ordered
Buying coins in the shop No, and money is involved TCP, over HTTPS to the shop service

Sequenced means: if a packet arrives that is older than the newest one already seen, throw it away. It costs nothing, and it stops a late snapshot from yanking kites backwards.

Inputs deserve a closer look. Each one matters, but waiting a round trip for a resend would make it arrive too late to be useful. So every input packet also repeats the previous three inputs. If one packet is lost, the next one, only a tick later, still delivers everything it carried, with no waiting at all.

TCP offers exactly one combination: reliable and ordered, for everything on the connection. That suits the shop and the lobby, and it is wrong for kite positions.

The shortcut

Ask the two questions in order, "Replaced?" then "Does order matter?", and the channel falls out.

Classifying "Match over: Blue team wins"Step 1 of 4
  1. Replaced?

    No later message makes the result pointless, so it must be reliable.

Drills

Answer fast — trust the rule.

quick drill

Which channel suits the kite-position snapshots?

quick drill

Which channel suits in-match chat lines?

quick drill

What does an unreliable, sequenced channel do with a packet older than the newest one it has already seen?

quick drill

Why does Manja Arena repeat the last three inputs in every input packet instead of resending lost ones?

quick drill

What combination does TCP give every message on a connection?

Remember

  • If a newer message replaces it, send it unreliable; if not, reliable.
  • Ask "Replaced?" and then "Does order matter?".
  • Trap: one channel for everything. All-reliable adds delay; all-unreliable loses events.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainPick a channel for each message

Classify these four Manja Arena messages, and explain the channel you would use for each: a kite-position snapshot, a player's steering input, a 'kite cut' event and a chat line.