Skip to main content

Introduction to Peer-to-Peer via a relay server

Last updated on September 10, 2024

Overview

AccelByte Gaming Services (AGS) Peer-to-Peer (P2P) provides low-level networking capabilities for games to implement secure peer-to-peer communication based on the WebRTC protocol.

These are the components that enable AGS P2P:

  • AGS Lobby, acting as a signaling server
  • TURN servers, hosted in AccelByte Multiplayer Servers (AMS)
  • AGS Session to manage and keep track of player sessions
  • The TURN manager service to manage and track all the TURN servers deployed in multiple regions (contact AccelByte for region selection)
  • Networking Utilities library (currently supporting Unreal and Unity)

Using the AGS P2P networking library, game clients can establish secure connections to other game clients (as peers). On the backend, AGS handles the handshake negotiation, secure address exchange (STUN), NAT traversals, and fallback to use a relay server (TURN) in case direct connection is not possible.

Common usage of the P2P networking library is for games that implement peer-hosted multiplayer sessions without a dedicated server. The AGS P2P networking library can be used in conjunction with both Unreal's Replication system and Unity's GameObjects.

Key concepts

The WebRTC, ICE, STUN, and TURN technologies are the basis of AGS P2P.

WebRTC is an open protocol standard to facilitate real-time communication between applications over the internet. WebRTC employs multiple protocols and techniques:

  • Interactive Connectivity Establishment (ICE), a technique to get two computers to communicate with each other and to deal with network address translators (NATs), firewalls, and other network barriers.

  • ICE uses various techniques such as exchanging network connectivity information via STUN -- Session Traversal of User Datagram Protocol (UDP) Through Network Address Translators (NATs) servers -- as well as relaying network traffic via TURN (Traversal Using Relays around NAT) servers.

AGS hosts these STUN and TURN servers, which are based on Google's COTURN project.

Read more:

Security

When a peer is attempting to connect to another peer, a handshake will be performed via a Signaling Server implemented within AGS Lobby. For security purposes, no public IP address will be exposed and exchanged between the peers.

Next steps

Source for the AGS Networking Utilities:

Sample projects on how to utilize the P2P Networking Library: