Class ReconnectPolicy

Namespace
Unity.Multiplayer.Core

When a client that lost its game should try to get back in, how often, and how long to wait between tries. A reconnect sends the same player token, so within the server's ReconnectGraceSeconds the player gets the same seat and player object back (see SeatRegistry).

public sealed class ReconnectPolicy
Inheritance
ReconnectPolicy
Inherited Members

Remarks

Only a connection that was lost is retried (TimedOut, TransportFailure). A server that shut down, a kick, a refusal and the player's own leave are final: retrying them would only fail again or undo what someone chose.

Fields

DefaultFirstDelaySeconds

public const double DefaultFirstDelaySeconds = 1

Field Value

double

DefaultMaxAttempts

Default MaxAttempts.

public const int DefaultMaxAttempts = 5

Field Value

int

DefaultMaxDelaySeconds

Default MaxDelaySeconds.

public const double DefaultMaxDelaySeconds = 8

Field Value

double

Properties

FirstDelaySeconds

Seconds before the first try; each later try waits twice as long as the one before.

public double FirstDelaySeconds { get; set; }

Property Value

double

MaxAttempts

Tries before giving up; 0 turns reconnecting off.

public int MaxAttempts { get; set; }

Property Value

int

MaxDelaySeconds

The longest wait between two tries.

public double MaxDelaySeconds { get; set; }

Property Value

double

Methods

DelayBefore(int)

Seconds to wait before try attempt (1-based): doubling from FirstDelaySeconds, capped at MaxDelaySeconds.

public double DelayBefore(int attempt)

Parameters

attempt int

Returns

double

Exceptions

ArgumentOutOfRangeException

attempt is less than 1.

IsLostConnection(DisconnectReason)

True for the reasons that mean the link was lost: TimedOut and TransportFailure.

public static bool IsLostConnection(DisconnectReason reason)

Parameters

reason DisconnectReason

Returns

bool

IsRetryable(Disconnection)

True when a failed reconnect try (disconnection) is worth another: the server could not be reached yet or the link failed again. A refusal (full, version, banned) or a kick ends the retries.

public static bool IsRetryable(Disconnection disconnection)

Parameters

disconnection Disconnection

Returns

bool

ShouldReconnect(Disconnection, bool)

True when a client whose session ended with disconnection should try to reconnect: it had been connected (wasConnected; a join that never got in is not retried), reconnecting is on, and the connection was lost rather than closed on purpose.

public bool ShouldReconnect(Disconnection disconnection, bool wasConnected)

Parameters

disconnection Disconnection
wasConnected bool

Returns

bool