Menu

Turn-based multiplayer that survives bad networks: the state model I use in Flutter
📰

Turn-based multiplayer that survives bad networks: the state model I use in Flutter

DEV Community: flutter·Youngjun Yoon·2 days ago
#a7ibwEQf
#devtoflutter#devto#dev#client#turn
Reading 0:00
15s threshold

I ship a turn-based artillery game — one player shoots, the other waits, then they swap. Turn-based sounds like the easy version of multiplayer. It is not; it just moves the difficulty from frame timing to state .

Here is the model I ended up with after shipping to Android and iOS, with a small player base on mobile networks that drop constantly. It is not clever. It is boring on purpose.

1. Sync inputs, not state

The temptation is to send the world state after every turn: tank positions, HP, terrain deltas. That works until two clients disagree by a rounding error and then diverge forever.

Instead the server keeps an append-only event log : shot(angle, power, itemUsed) , surrender , turnTimeout . Each client replays the log locally and computes the outcome itself.

Two benefits:

Payload is tiny (a shot is a few dozen bytes, not a terrain diff).

A reconnecting client can be caught up by replaying events, not by rebuilding the world.

2.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.