How Web Developers Keep Online Gaming Sessions Alive Through Flaky Connections
A player on a train enters a tunnel. A laptop switches from one Wi-Fi access point to another. A phone moves from Wi-Fi to mobile data as someone walks out of the house.

A player on a train enters a tunnel. A laptop switches from one Wi-Fi access point to another. A phone moves from Wi-Fi to mobile data as someone walks out of the house. In each case, the network connection under a browser game disappears for somewhere between half a second and half a minute. Whether the player experiences that as a brief hiccup or a lost match depends almost entirely on decisions the web developer made months earlier.
Players care deeply about uninterrupted access. They compare which games survive a shaky connection, they read reviews about stability, and many keep a handful of links promising smooth access, such as ankertoto, while looking for a game that does not kick them out. For developers, building for flaky connections is less about any single technology and more about assuming the network will fail and designing the recovery path first.
Detecting a dead connection quickly
The first problem is knowing the connection has gone. A WebSocket can sit in an open state for a surprisingly long time after the network beneath it has vanished, because TCP will not notice until a send fails or a timeout expires, which can take minutes. Relying on the browser's close event alone leaves players staring at a frozen screen.
The standard fix is an application-level heartbeat. The client sends a small ping message every few seconds, and the server replies. If two or three replies are missed in a row, the client treats the connection as dead and starts recovery. A heartbeat interval of 2 to 5 seconds with a three-miss threshold detects most dead connections within 15 seconds, while adding negligible traffic. The browser's online and offline events are a useful hint as well, though they only report whether a network interface exists, not whether the internet is reachable.
Reconnecting without stampeding the server
Once a dead connection is detected, the client needs to reconnect. The naive approach is to try again immediately and keep trying in a tight loop. That works for one player and fails catastrophically for thousands. If a server restarts or a regional network blip disconnects everyone at once, a tight retry loop from every client produces a flood of connection attempts that can knock the recovering server over again.
Exponential backoff with jitter solves this. The client waits a short time before the first retry, roughly doubles the wait after each failure, caps it at a sensible maximum, and adds a random offset so clients do not retry in sync.
- First retry after 250 to 500 milliseconds.
- Double the base delay after each failure: 1 second, 2 seconds, 4 seconds.
- Cap at around 15 to 30 seconds.
- Add random jitter of up to 50 percent of the current delay.
- Reset the delay once a connection has stayed healthy for a minute.
The same pattern protects HTTP APIs, and it pairs naturally with server-side protections like those in our article on rate limiting that does not punish real users.
Resuming the session, not restarting it
Reconnecting the socket is only half the job. The player needs to land back in the same match with the same state. That requires a session token that survives the disconnect and a server that holds the player's slot for a grace period, typically 30 to 90 seconds depending on the game.
On reconnect, the client presents its token and the sequence number of the last message it processed. The server then sends either the missed messages or a fresh snapshot of the game state, whichever is smaller. Games with frequent state updates usually send a snapshot; turn-based games can replay missed events. Either way, the player should see a brief "reconnecting" indicator and then continue, not a lobby screen.
Local storage can help bridge longer gaps. Saving the session token and some interface state locally means that even a full page reload after a crash can resume the match. Our piece on how local storage keeps browser game progress explains the trade-offs.
The fallback that often makes things worse
A common recommendation is to fall back from WebSockets to HTTP long polling when the socket connection fails, on the assumption that something is better than nothing. Long polling was valuable when proxies and firewalls routinely blocked WebSockets. Today, support is nearly universal, and a socket failure usually means the network is down, not that WebSockets are blocked.
Falling back to polling in that situation adds complexity, doubles the number of code paths to test, and can leave clients stuck on a slower transport after the network recovers. A better default is to retry WebSockets with backoff, and only use a fallback transport after repeated failures on a network where plain HTTP requests are succeeding.
Designing the interface around interruptions
Technical recovery means little if the interface panics. A few design choices make interruptions feel smaller to the player:
- Show a calm reconnecting indicator immediately, with a counter, rather than a blank screen.
- Keep rendering the last known state so the scene does not vanish.
- Queue player inputs during short gaps and send them on reconnect if the game rules allow it.
- Tell the player clearly if their slot expired, and offer a one-tap path back into a new match.
Handling the switch between networks
Mobile players face a specific problem that desktop players rarely see: the device changes networks mid-session. When a phone moves from Wi-Fi to mobile data, its IP address changes, and every existing TCP connection, including the game's WebSocket, becomes invalid. From the server's point of view, the old connection simply stops responding, and a new one arrives from a different address a few seconds later.
Servers that tie a session to an IP address will treat the new connection as a stranger, which is one of the most common causes of players being thrown out of matches while walking out of their homes. Tying the session to a token instead of an address avoids this. Some newer transports, such as WebTransport over QUIC, can survive address changes at the protocol level, but browser support and infrastructure requirements are still uneven, so the token-based resume path remains the dependable baseline.
Testing with real bad networks
Most developers test on fast, stable office connections, which is exactly the environment where none of this code runs. The browser's DevTools can simulate offline mode and throttled networks, and several tools can inject packet loss and latency at the operating system level. A useful exercise is to play a full match while toggling airplane mode for five seconds every minute. Any bug that appears there will appear for real players on trains, buses, and crowded home networks every day.
Building this resilience takes effort, but players notice the result immediately. A game that quietly survives a tunnel earns a kind of loyalty no feature list can buy.
More in Games
Games
How WebRTC Data Channels Power Real Time Online Games
Most guides to real time play on the web stop at the web socket, and for a chat box or a turn based board that is usually...
Games
Why Memory Leaks Slow Down Long Online Game Sessions
A browser game can feel perfect in a two minute demo and fall apart after an hour.
Games
How The Web Audio API Drives Sound In Online Games
Sound is the part of a browser game that players feel before they can explain it.