Game Networking Intro
A single-player game has one copy of the world. An online game has several copies, one on every machine, and they are never quite the same: each one learns about the others' actions tens or hundreds of milliseconds late, some messages never arrive, and some players actively try to lie. Multiplayer game networking is the craft of hiding that from the player. Done well, a shooter feels instant at 120 ms ping. Done badly, players rubber-band, shoot at ghosts and quit.
This course is about the techniques that make real-time multiplayer work, not about networking in general. For IP addresses, routing, TCP's handshake, sockets and DNS, take Computer Networking first or alongside; we only revisit what games use differently.
What this course covers
| Section | Question it answers | Main techniques |
|---|---|---|
| Foundations | How do bytes get from A to B, and how late? | UDP vs TCP, latency/jitter/loss, tick rate and clock sync, bit-packing, delta compression, bandwidth budgets, acks over UDP |
| Architectures | Who decides what is true? | peer-to-peer vs client-server, the authoritative server, deterministic lockstep, rollback, snapshots |
| Real-time techniques | How do we hide the lag? | interpolation, extrapolation, client prediction, server reconciliation, lag compensation, interest management |
| Security | What if the client lies? | server validation, cheat types, rate limiting |
| Backend | Everything around the match | accounts (with the TAD identity server as a case study), lobbies, matchmaking, dedicated servers, persistence |
| Engines | How do real engines do it? | Unity Netcode for GameObjects, Mirror, FishNet, Photon Fusion, Unreal replication, Godot's MultiplayerAPI, WebSocket, WebRTC, Colyseus |
Two kinds of examples run in the lessons:
- Deterministic models in TypeScript and C#. The network is simulated with a fake clock and a seeded random generator for loss and jitter, so the output is the same on every run and you can follow a packet tick by tick.
- The lag simulator, a page with two simulated clients and an authoritative server. You drive one client with the keyboard, set latency, jitter and loss with sliders, and switch prediction, reconciliation and interpolation on and off. It grows over the Real-Time Techniques section and becomes the mini project arena.
The core problem in 30 lines
Here is the whole difficulty in one model. A server runs the game at 20 ticks per second. A client 100 ms away holds Right for half a second. The client sends inputs, the server moves the player and sends the position back. The client draws whatever it last heard:
const TICK_MS = 50; // server ticks at 20 Hz
const ONE_WAY_MS = 100; // 200 ms round trip
const SPEED = 4; // units per tick
type Msg = { arrive: number; value: number };
const toServer: Msg[] = []; // inputs in flight
const toClient: Msg[] = []; // positions in flight
let serverX = 0, shownX = 0;
for (let t = 0; t <= 600; t += TICK_MS) {
const holding = t < 500 ? 1 : 0; // the player holds Right for 500 ms
toServer.push({ arrive: t + ONE_WAY_MS, value: holding });
while (toServer.length && toServer[0].arrive <= t) { // server: apply inputs that have arrived
serverX += toServer.shift()!.value * SPEED;
}
toClient.push({ arrive: t + ONE_WAY_MS, value: serverX });
while (toClient.length && toClient[0].arrive <= t) { // client: show the latest position heard
shownX = toClient.shift()!.value;
}
console.log(`t=${String(t).padStart(3)} ms key ${holding ? 'held' : 'up '} server x=${String(serverX).padStart(2)} client shows x=${String(shownX).padStart(2)}`);
}t= 0 ms key held server x= 0 client shows x= 0
t= 50 ms key held server x= 0 client shows x= 0
t=100 ms key held server x= 4 client shows x= 0
t=150 ms key held server x= 8 client shows x= 0
t=200 ms key held server x=12 client shows x= 4
t=250 ms key held server x=16 client shows x= 8
t=300 ms key held server x=20 client shows x=12
t=350 ms key held server x=24 client shows x=16
t=400 ms key held server x=28 client shows x=20
t=450 ms key held server x=32 client shows x=24
t=500 ms key up server x=36 client shows x=28
t=550 ms key up server x=40 client shows x=32
t=600 ms key up server x=40 client shows x=36
The key goes down at 0 ms, but the player sees nothing move until 200 ms, a full round trip. When the key is released at 500 ms, the character keeps sliding for another 200 ms. Every technique in this course attacks some part of that picture:
- Client prediction moves the local player immediately, without waiting for the server.
- Server reconciliation fixes the prediction when the server disagrees.
- Interpolation makes other players move smoothly even though their updates arrive in bursts.
- Lag compensation lets the server judge a shot by what the shooter actually saw.
Words you will meet
| Term | Meaning |
|---|---|
| Latency / ping / RTT | one-way delay; ping usually means the round-trip time (there and back) |
| Tick | one fixed simulation step on the server (e.g. 30 or 60 Hz) |
| Authority | the machine whose copy of some state is the truth (usually the server) |
| Snapshot | the server's copy of the world state at one tick, sent to clients |
| Replication | engines' word for copying state from the authority to everyone else |
| RPC | remote procedure call: "run this function on that machine" |
| Input delay | waiting a few ticks before applying inputs, so everyone has them |
| Netcode | players' word for all of the above, usually said angrily |
How to take this course
- Read Foundations and Architectures in order; the later lessons build on them.
- In Real-Time Techniques, play with the simulator in each lesson at 150 ms and 2% loss, the setting we use throughout. If a technique looks fine at 0 ms, that tells you nothing.
- Then read the engine lesson for the engine you use (Unity, Unreal, Godot or the web). They map each idea onto the real API.
- Finish with the exercises and the arena mini project.
Tip: If you are new to game loops, fixed timesteps or state machines, do Game Development Fundamentals first. Networked games are built on a fixed-tick simulation, and that is much easier to learn offline.
Test yourself
A client has a 200 ms round-trip time and waits for the server before moving its own character. When does the character start moving after the key goes down?
- Immediately
- After about 100 ms
- After about 200 ms
- After one server tick
Which technique makes the local player's own character respond instantly to input?
- Entity interpolation
- Client-side prediction
- Lag compensation
- Interest management
What does 'authority' mean in game networking?
- The player with the best ping
- The machine whose copy of a piece of state is treated as the truth
- The matchmaking server
- The fastest tick rate