The Relay service facilitates multiplayer support without dedicated game servers by allowing players to communicate with each other through Relay servers. Relay servers deliver messages between connected players using low-latency datagram exchange between game clients, so no two players ever connect directly to each other. Relay servers are ideal for games that use a listen server pattern where one player (the host player) acts as the “server” and the other players (the joining players) act as “clients.”
Relay servers act as public endpoints reachable by all players. This design addresses common issues of changing networks and IP addresses, network address translation (NAT), and firewalls between players. Each player can connect to the same IP address and port (the selected Relay server’s IP address and port), and game clients can trust that the connection information remains the same throughout the game session. Through this indirection, players in a game session don't need to know each other's IP address, thereby increasing security and privacy.
The host player’s game client defines the maximum number of players the game session supports when it creates an allocation.
Relay server lifecycle
Relay servers are designed as long-running and multi-tenanted connection points. As a result, the Relay server lifecycle is independent of the game session lifecycle.
A Relay server disconnects a player if the player connection times out. The default time to live (TTL) before Relay disconnects a client is 10 seconds. The disconnect TTL is 60 seconds when the host in alone (after the
BIND message but before a peer connects to them with a
CONNECT message). To prevent an unintended timeout, the game client can send periodic
PING messages to the Relay server to keep the connection alive.