How Multiplayer Works
What really happens when two players share the same game world?
What really happens when two players share the same game world?
Two ways to get updates from a server. Watch both run side by side and see why multiplayer games need WebSockets.
The client repeatedly asks "anything new?" even when nothing changed. Wasteful and always delayed by the polling interval.
A persistent connection stays open. The server pushes updates the instant they happen. No delay, no wasted requests.
Click or tap anywhere in the box to move your character. Then drag the latency slider up and try again.
The time for data to travel from your computer to the server and back. Also called "ping." Even at light speed, distance adds delay.
Same city: ~10ms. Cross-country: ~50ms. Across the ocean: ~150ms. That is why game servers are placed in multiple regions.
Should the player's computer or the server decide where characters are? Click anywhere to move, then try the "cheat" button.
The player's computer decides where they are. Fast and responsive, but cheaters can teleport, speed hack, or walk through walls.
The server validates every move. Cheating is impossible because the server rejects invalid positions. Slightly more latency but secure.
The server only sends updates 10 times per second. Watch what happens without prediction vs with it. The blue dot is a remote player moving in a circle.
Characters jump between positions every server tick. It looks choppy and robotic, even at 10 updates per second.
The client smoothly animates between known server positions. The movement looks fluid even though updates are infrequent.
You've seen the core mechanics behind every online multiplayer game: real-time connections, latency compensation, server authority, and prediction. These same techniques power everything from simple chat apps to massive battle royales.
WebSockets keep a persistent connection open so data flows instantly, unlike HTTP polling which asks "anything new?" over and over.
Even 100ms of delay completely changes how a game feels. Every multiplayer game fights latency constantly.
The server is the single source of truth. If the client could decide where players are, cheating would be trivial.
Client-side prediction and interpolation hide latency by guessing where things should be, then correcting when the server responds.
Put your new knowledge into practice!