Reliability — Only Where You Need It
"Kite 9 was cut by kite 4" must reach all 16 players. The kite positions for tick 300 need not: by the time anyone could resend them, the positions for tick 301 are already on their way. UDP lets Manja Arena treat these two messages very differently, but only because the game builds the reliability itself.
The rule
Number every packet; resend only what is still worth having.
The pieces fit together like this:
- Sequence numbers. Each packet carries its own 16-bit number, one higher than the last. After 65,535 the counter wraps back to 0, so "is this newer?" must be worked out with that wrap in mind.
- Acks that ride along. Both sides send packets every tick anyway, so each packet also carries an ack, the newest packet number received from the other side, and ack bits: 32 bits where bit n means "I also received packet ack − 1 − n". A single packet can confirm up to 33 packets, and no separate acknowledgment packets are needed.
- Remember what each packet carried. The sender keeps a note per packet, such as "packet 105 held the snapshot for tick 305 and the event kite 9 cut".
- Decide on loss. If a packet is still unconfirmed after roughly one round trip plus a safety margin, treat it as lost. Its reliable messages go into the next packet; its unreliable ones are forgotten, because something fresher has already been sent.
Reliable messages also carry a message number of their own. If both the original and a resend turn up, the receiver spots the duplicate and drops it, and it can apply events in the order they were sent.
The same packet can now mix both kinds: a fresh snapshot that nobody will ever resend, and an event that will keep being resent until it is confirmed.
The shortcut
To read ack bits, write them with bit 0 on the right and count backwards from ack − 1, one packet per bit.
Bit 0 is 1
Packet 106 arrived. (Packet 107 arrived too, or it would not be the ack.)
The trap is making everything reliable "to be safe". Resending stale snapshots and making later messages wait for them rebuilds TCP's delays on top of UDP.
Drills
Answer fast — trust the rule.
A packet from the client says ack = 50, and only bit 0 of its ack bits is set. Which packets does it confirm?
Packet 105 was lost. It carried a snapshot of kite positions. What should the server do about that snapshot?
Which Manja Arena message must be resent if the packet carrying it is lost?
Sequence numbers are 16 bits. Which number comes right after 65,535?
Why does Manja Arena need no separate acknowledgment packets?
Remember
- Number every packet; resend only what is still worth having.
- Read ack bits right to left, counting back from ack − 1.
- Trap: making everything reliable, which rebuilds TCP's delays on top of UDP.
