The simple way :
- Client sends inputs to the host.
- host processes inputs.
- host calculates the game state (positions of objects).
- host sends game state to clients.
Example : The original Quake networking (for LAN games).
Advantages : simple.
Disadvantages : lag becomes a serious issue. Round-trip latencies will make the client input laggy.
The way it is corrected :
- client reads his inputs, and calculates a local prediction of the player position.
- client sends inputs to the host, as well as his local prediction calculation. The input+prediction packet is marked with a unique number (aka Sequence Number, aka SQN).
- client also stores the input+prediction packet in a buffer.
- Host receives the client inputs+prediction+SQN.
- host calculate the real player position, using those inputs.
- host then compares the player location with the client prediction.
- if a difference is detected (within an arbitrary margin of error), the host sends a correction packet back to the client (containing corrected_position+SQN).
- client receives the correction packet.
- client looks up the original input+prediction packet in his buffer, using the SQN.
- client substitutes the predicted position with the corrected position.
- client then replays his input stack from that point onwards, to adjust his current prediction with the server correction.
Example : Counterstrike, Quake 3, Unreal Tournament, Team Fortress...
Advantages : Nullify the input latency, by allowing the client to locally predict the effect of the player's inputs.
Disadvantages : client will experience jitter and rubber-banding when a discrepancy between the client prediction and the server calculation is detected (i.e. two players jumping on top of each other).