Class HealthEndpoint
- Namespace
- Unity.Multiplayer.Core
The server package's health endpoint: a tiny HTTP/1.1 server on its own TCP port that answers
GET /healthz (and GET /) with a HealthReport: 200 while running, 503 while starting or
stopping. Docker's HEALTHCHECK, a load balancer or a deploy tool probes it. Anything else gets 404 or 405.
public sealed class HealthEndpoint : IDisposable
- Inheritance
-
HealthEndpoint
- Implements
- Inherited Members
Remarks
Engine-free and thread-based: the report callback runs on a pool thread, so hand it a snapshot the game updates on its own thread (Volatile reads of an immutable report are enough). Each request gets one response and the connection closes.
Constructors
HealthEndpoint(Func<HealthReport>)
Creates an endpoint that serves what report returns.
public HealthEndpoint(Func<HealthReport> report)
Parameters
reportFunc<HealthReport>
Exceptions
- ArgumentNullException
reportis null.
Properties
IsRunning
True while listening.
public bool IsRunning { get; }
Property Value
Port
The port it listens on (the one chosen by the system when started on 0); 0 when stopped.
public int Port { get; }
Property Value
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Respond(string, HealthReport)
The whole HTTP response to requestLine (such as GET /healthz HTTP/1.1), headers and
body. The endpoint's logic, without sockets.
public static string Respond(string requestLine, HealthReport report)
Parameters
requestLinestringreportHealthReport
Returns
Start(int, IPAddress)
Starts listening on port (0 picks a free one) on every interface, or on address.
public void Start(int port, IPAddress address = null)
Parameters
Exceptions
- InvalidOperationException
It is already running.
- SocketException
The port is taken.
Stop()
Stops listening. Safe to call more than once.
public void Stop()