Class RendezvousJoinCodeService

Namespace
Unity.Multiplayer.Core

The IJoinCodeService over the self-hosted rendezvous service (RFC 0001): the default for dedicated servers. A server registers its public endpoint (RegisterAsync(ServerAdvertisement, CancellationToken)) and this service keeps the registration alive with heartbeats until it is revoked or the service is disposed; a client resolves a code to the server's address and port.

public sealed class RendezvousJoinCodeService : IJoinCodeService, IDisposable
Inheritance
RendezvousJoinCodeService
Implements
Inherited Members

Remarks

The rendezvous service maps codes to addresses; it does not get through NAT, so it suits servers with a reachable port (a VPS, or a port-mapping host such as RunPod), not a listen server at home.

Heartbeats run on the thread pool every third of the registration's TTL. A transient failure (unreachable, 429, 5xx) is retried at the next beat; a registration the service no longer knows (it expired while the service was unreachable, or the service restarted) raises RegistrationLost and stops beating. Events are raised on the thread pool.

Constructors

RendezvousJoinCodeService(string, string)

Uses the service at baseUrl; secret is the operator's registration secret (servers only).

public RendezvousJoinCodeService(string baseUrl, string secret = null)

Parameters

baseUrl string
secret string

Exceptions

ArgumentException

baseUrl is not an absolute http(s) URL.

RendezvousJoinCodeService(RendezvousClient, string, bool)

Uses client; disposes it only when ownsClient is true.

public RendezvousJoinCodeService(RendezvousClient client, string secret = null, bool ownsClient = false)

Parameters

client RendezvousClient
secret string
ownsClient bool

Exceptions

ArgumentNullException

client is null.

Fields

MinHeartbeatInterval

The shortest gap between heartbeats, whatever the TTL.

public static readonly TimeSpan MinHeartbeatInterval

Field Value

TimeSpan

Properties

Client

The client this service talks through.

public RendezvousClient Client { get; }

Property Value

RendezvousClient

LiveCount

How many registrations this service is keeping alive.

public int LiveCount { get; }

Property Value

int

Methods

Dispose()

Stops every heartbeat and makes a best-effort attempt (up to 2 s) to delete every live registration; anything not deleted expires by itself after its TTL.

public void Dispose()

HeartbeatInterval(int)

The gap between heartbeats for a ttlSeconds TTL: a third of it, at least MinHeartbeatInterval.

public static TimeSpan HeartbeatInterval(int ttlSeconds)

Parameters

ttlSeconds int

Returns

TimeSpan

PublishAsync(JoinTarget, CancellationToken)

Registers an endpoint target (Endpoint) and keeps it alive.

public Task<JoinCode> PublishAsync(JoinTarget target, CancellationToken cancellationToken = default)

Parameters

target JoinTarget
cancellationToken CancellationToken

Returns

Task<JoinCode>

Exceptions

NotSupportedException

target is a relay target.

ArgumentNullException

target is null.

NotSupportedException

This service cannot publish that Kind.

RegisterAsync(ServerAdvertisement, CancellationToken)

Registers a dedicated server's public endpoint and keeps it alive. A null Address lets the service record the address the request came from.

public Task<JoinCode> RegisterAsync(ServerAdvertisement advertisement, CancellationToken cancellationToken = default)

Parameters

advertisement ServerAdvertisement
cancellationToken CancellationToken

Returns

Task<JoinCode>

Exceptions

ArgumentNullException

advertisement is null.

RendezvousException

The service refused (wrong secret, bad endpoint, full) or could not be reached.

ObjectDisposedException

The service was disposed.

ResolveAsync(JoinCode, CancellationToken)

The target code leads to, or null when it is unknown, revoked or expired.

public Task<JoinTarget> ResolveAsync(JoinCode code, CancellationToken cancellationToken = default)

Parameters

code JoinCode
cancellationToken CancellationToken

Returns

Task<JoinTarget>

RevokeAsync(JoinCode, CancellationToken)

Stops keeping code alive and deletes it. False when this service did not publish it or it was already gone.

public Task<bool> RevokeAsync(JoinCode code, CancellationToken cancellationToken = default)

Parameters

code JoinCode
cancellationToken CancellationToken

Returns

Task<bool>

Exceptions

RendezvousException

The service could not be reached (the registration then expires by itself).

Events

HeartbeatSent

A heartbeat renewed a registration.

public event Action<JoinCode> HeartbeatSent

Event Type

Action<JoinCode>

RegistrationLost

A registration this service was keeping alive is gone (the code no longer resolves); with why.

public event Action<JoinCode, string> RegistrationLost

Event Type

Action<JoinCode, string>