Multiplayer tutorial 1: concepts

60

Index

Stats

83,205 visits, 354,644 views

Tools

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 3 Mar, 2014. Last updated 12 Sep, 2023

The chaos of the Internet

Suppose now that some peers have joined the same room, successfully connected to a host, and a multiplayer game has begun. We can now ignore the signalling server: it is no longer involved from this point. (Your game can disconnect everyone from the signalling server at this point, but note that prevents anyone joining the game late.)

As described earlier, the multiplayer game itself runs with the host acting as the server. Peers only send data to the host, whereas the host can send data to anyone. This means if two peers want to communicate, it must be relayed through the host.

Multiplayer games would be a lot simpler if all transmission over the Internet was near-instant. This is generally the case on local area networks (LAN), such as your home or office network. However the Internet is phenomenally complex. Between any two players on the Internet, there could be 10-20 network devices (such as routers). The devices along this route will be different for each pair of players. For every single message sent, each device along the route must receive an incoming packet of information, read and understand its destination, determine where to forward it on to, and then re-transmit it. On top of that if you connect to a player overseas, your data will most likely be travelling through undersea cables, which deal with extraordinary amounts of traffic over large distances.

Amazingly, each device on the route can often forward on an incoming packet within milliseconds. However with lots of devices along a route, this adds up. If any device along the way is experiencing high load, it could slow down resulting in longer transmission delays. These devices, like any computers, can also crash, run out of memory, shut down for maintenance, lose power, run in to bugs that affect service, and so on. Due to much impressive engineering, routers can often re-route data around devices that have gone offline, or even re-route data down faster alternative paths. All of this can add temporary or permanent changes to the time it takes a message to travel from A to B.

The laws of physics must also be taken in to account. If a player from London in the UK connects to Sydney in Australia, the data must travel approximately 17,000km. Travelling in a straight line at the speed of light, this would take around 57ms. It is physically impossible to get data there faster than that. Then the cables along the way probably aren't perfectly straight, and over such a long distance there are likely to be many more routing devices.

Next Tutorial In Course

Multiplayer tutorial 2: chat room 12:47

Learn how to build a simple chat room, which is the most basic kind of multiplayer example.

  • 27 Comments

  • Order by
Want to leave a comment? Login or Register an account!