Automatic Behaviour
The protocol has several rules a client must follow to keep a search alive. The SDK follows them for you, so you don't write code for any of this.
What the SDK does for you
-
A ticket per attempt. Every connection attempt, including each reconnect, asks your ticket provider for a new ticket, because tickets are single-use and expire after 5 minutes. See Generate a Ticket.
-
Ping checks. For ping-based game modes, the server sends a
PINGand the SDK replies immediately. The server measures round-trip time from its own clock, so the SDK needs to answer quickly and has nothing else to do. -
Heartbeats. A heartbeat is sent every 45 seconds while searching, so the search doesn't expire. See Heartbeats & Disconnects.
-
Reconnects. If the connection drops mid-search, the SDK reconnects with a new ticket and sends
begin_searchagain for the same game mode. Within about 30 seconds of the drop, the server resumes the held search with its original search time, so the player doesn't lose their place. -
Backoff. Retries wait 1 second, then double up to a 16-second cap. Once a reconnected connection has stayed up for a full heartbeat interval, the next drop starts again from 1 second. Retries continue until you call
CancelSearchAsyncorCloseAsync. -
Recovering from a stale pong. If the server reports that a
pongdidn't match a pending ping check (STALE_PONG), the SDK re-sendsbegin_search. -
Party members. A party member never calls
BeginSearchAsync. The SDK starts their heartbeats whenSEARCH_STARTEDarrives, and answers a ping check with the party's game mode.
It doesn't reconnect a connection opened with ConnectAsync: the server removes a disconnected
player from their party, so there is nothing to resume. The state becomes Closed and
Party is cleared. See Parties.
It doesn't reconnect after a terminal error or a superseded search, because the server ended those on purpose. See Error Handling and Events & States.
Tuning
Pass a MatchmakingClientOptions to Initialize to change the defaults:
_matchmaking.Initialize(tickets, new MatchmakingClientOptions
{
HeartbeatInterval = TimeSpan.FromSeconds(30),
InitialReconnectDelay = TimeSpan.FromSeconds(2),
MaxReconnectDelay = TimeSpan.FromSeconds(30),
MaxReconnectAttempts = 5, // default: null, which retries until cancelled
});| Option | Default | Notes |
|---|---|---|
HeartbeatInterval | 45 seconds | Searches expire after 3 minutes without a heartbeat, so keep this well under that. |
InitialReconnectDelay | 1 second | The wait before the first retry. |
MaxReconnectDelay | 16 seconds | The cap on the doubling backoff. |
MaxReconnectAttempts | none | Stop retrying after this many consecutive attempts and move to Closed. The count restarts when a reconnected connection stays up for a full heartbeat interval. null retries indefinitely. |
The backoff policy is the SDK's own choice. The protocol only requires that clients back off between attempts.
Next
Once a match is made, your game still needs somewhere to play it: After a Match.