How Multiplayer Browser Games Work
Playing against another person inside a web page feels like magic, but the idea is straightforward. This article explains how two browsers find each other, who runs the match and what happens when somebody leaves, using this site as the example.
Finding each other
Two browsers cannot simply find one another on the internet. A small public signaling service helps them exchange connection details. In Quick Play, the first browser to arrive registers itself as the host for that game mode and the next browser that arrives connects to it. If nobody connects within about four seconds, the computer opponent steps in so you are never left waiting. For private rooms, the host registers under a four-digit code, and your friend uses that code to find the room.
The host runs the match
After the connection is made, one browser, the host's, runs the official version of the match: movement, bullets, damage, medkits and the shrinking circle in Battle Royale. The other player, the guest, sends simple inputs about thirty times per second, including movement direction, aim angle and whether the trigger is held. The host sends back snapshots of the world about twenty times per second. Having one authority prevents two players' computers from disagreeing about who hit whom.
Rooms, locks and leaving
A private room locks to the first person who joins using a private identifier stored on that device. A second person who tries the same code is turned away. If a guest leaves a private room, the host returns to the waiting screen. If a guest leaves a Quick Play match, the computer takes over their slot. If the host leaves, the guest sees a message and returns to the lobby, because the host was running the match.
Chat and voice
Chat messages and voice audio travel directly between the two browsers. They only appear when a real person is connected. Voice starts only after you press the microphone button and allow access in your browser. Read the Privacy Policy for the details of what is visible to your opponent, such as your IP address in a direct connection.
Why this approach
Direct connections keep latency low and let a small website offer multiplayer without running game servers. The trade-off is that your experience depends on both players' connections. See how to reduce lag and our technical overview of HTML5 games for more.
Frequently asked questions
Can strangers join my private room? Only someone who knows the four-digit code, and the room locks to the first person who enters.
Why did the game say Host left the match? The host's browser runs the match, so when the host closes the page or loses connection the game ends for the guest.
Does the site store my chats? No. Messages go directly between players and are not recorded by us.
Keep reading
- The Evolution of Casual Browser Games
- Tips for Better Reflexes in Arcade Games
- How Modern HTML5 Games Run Without Lag
- A Beginner's Guide to Top-Down Shooters
- Strategy Guide: How to Win in Every Game Mode
- A Beginner's Guide to Browser Gaming
- How to Improve Aim in Browser Shooter Games
- How to Reduce Lag and Understand Ping
- Browser Gaming on Mobile vs Desktop
- How to Fix Browser Game Loading Problems
- Common Mistakes New Gamers Make
- Classic Duel Strategy Guide
- Battle Royale Beginner Guide
- Sniper Outpost Guide
- Shotgun Corridor Strategy Guide