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
Default FirstDelaySeconds.
public const double DefaultFirstDelaySeconds = 1
Field Value
DefaultMaxAttempts
Default MaxAttempts.
public const int DefaultMaxAttempts = 5
Field Value
DefaultMaxDelaySeconds
Default MaxDelaySeconds.
public const double DefaultMaxDelaySeconds = 8
Field Value
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
MaxAttempts
Tries before giving up; 0 turns reconnecting off.
public int MaxAttempts { get; set; }
Property Value
MaxDelaySeconds
The longest wait between two tries.
public double MaxDelaySeconds { get; set; }
Property Value
Methods
DelayBefore(int)
Seconds to wait before try attempt (1-based): doubling from FirstDelaySeconds, capped at MaxDelaySeconds.
public double DelayBefore(int attempt)
Parameters
attemptint
Returns
Exceptions
- ArgumentOutOfRangeException
attemptis 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
reasonDisconnectReason
Returns
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
disconnectionDisconnection
Returns
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
disconnectionDisconnectionwasConnectedbool