GitHub Icon

Platform

Solutions

Resources

Company

STUN Servers for Peer-to-Peer Networking in Multiplayer Games

What are STUN Servers?

First, we need to understand how peer-to-peer (P2P) networking works in a multiplayer games.

The game creates a listen server and with the public IP you connect all players to the server.

Unfortunately, the truth isn't as easy as it seems because your public IP is not your own public IP. Your IP address is actually shared as your Internet provider groups multiple users under single IP with a process called network address translation.

The only difference is the port number which is temporarily assigned to you when you request a webpage or other resource.

For non-engineers, think of the server's IP as an apartment block. However, as there are multiple flats in each building. Every time you order a pizza, you are given a unique number for your flat, and the number changes over time.

And this causes a lot of confusion.

We need to find a mechanism to get the number assigned and share this information somehow with other players.

This solution is called a STUN server.

Think about it as Yellow Pages. If you want people to be able to find your business, you have to update the Yellow Pages with your current number.

Are STUN Servers for Multiplayer Games Safe?

Unfortunately, this solution is not secure, because our “flat number” could be shared further, and anyone from the internet could send anything to us.

Most of the service providers find this unsecured and block this kind of traffic.

The only alternative we have, are relay servers.

Your private address is not shared with anyone except the server which relays the information between you and the other player.

---

For more information on the comparison between Peer-to-Peer Networking, Relays and Authoritative Severs (often called Dedicated Servers), check out our dedicated breakdown on our blog.  

---

Parts of the above information comes from a presentation done by Michal Buras, Senior Developer at Highwire Games, at the Live Service Game Summit conference.

A full version of this conference can be found here: Peer-to-Peer, Relays & Container Instances: And In-Depth Analysis of Development Resources, Performance, Security Issues for Multiplayer Games