How do Video Games Stay in Sync? An Intro to the Fascinating Networking of Real Time Games.
Have you ever wondered how real-time games can keep multiple clients in sync even when there are large latencies between users? How can you see other players reacting to your actions near instantly, in spite of the fact that the communication between your computer and the server is not instant?
In one of my recent personal projects I made a game engine with real-time networking. In this article I’ll break down what I learned and what you’ll have to consider if you’d like to do the same.
Understanding The Problem
Firstly, lets get a concrete example of what issue we intend to solve. Almost all real-time video-games consist of a collection of clients and a single server that runs the game. The server is the “source of truth” for the system through which all communication must flow. Clients are only connected to each other through the server itself, which operates as a relay between them.
Collections of data are sent in discrete chunks to and from each client to keep them updated as the game unfolds. Another player moved? Send everyone else a message to keep them updated. A new player joined? Every client is notified. But key here, is that messages take time and are not free. They have real transit…