IAR51Client
namespace AR51.Net;
public interface IAR51Client : IAsyncDisposable
Implements: IAsyncDisposable
Dispose it with await using (or DisposeAsync): this stops every stream and closes every connection. Calling it again does nothing.
The AR 51 system: finds the server, connects, and gives you every service through one object. Create one with AR51Client.Create, subscribe to what you need, then call StartAsync.
All members are safe to call from any thread. While started, the client reconnects by itself whenever the server restarts or the network drops. Create one client and keep it for the life of your application.
This page is reference (facts only). For a walkthrough with a complete sample, see the Connecting guide.
Properties
| Property | Type | Access | Description |
|---|---|---|---|
State | ConnectionState | get | The current connection state. |
ServerEndPoint | IPEndPoint? | get | The address of the AR 51 server this client is connected to, or null while it is not connected. |
Skeletons | ISkeletonClient | get | Live skeletons of the people the system tracks. Started and stopped together with this client; it can also be stopped and started on its own. |
ObjectDetection | IObjectDetectionClient | get | Live tracked objects, for example props. Started and stopped together with this client; it can also be stopped and started on its own. |
Servers | IServerClient | get | The AR 51 server machines: status, launch and quit the server program, start and stop tracking. |
Cameras | ICameraClient | get | The cameras: list with calibration values, live preview, image settings and auto-tune. |
Calibration | ICalibrationClient | get | Camera calibration and the tracked area (capture bounds). |
Recording | IRecordingClient | get | Recording of camera video and tracking data on the servers. |
Devices | IDeviceClient | get | The apps and devices connected to the system: headsets, Unity and Unreal apps, phones and Mocap Studio. |
Method summary
| Method | Returns | |
|---|---|---|
StartAsync | Task | |
StopAsync | Task |
→ Full descriptions in Method details below.
Events
Standard .NET events (EventHandler<T>): subscribe with +=, unsubscribe with -=. They are raised on a background thread.
| Event | Args | Raised when |
|---|---|---|
ConnectionStateChanged | ConnectionStateChangedEventArgs | Raised when State changes. Raised on a background thread. |
ar51.ConnectionStateChanged += (_, e) =>
Console.WriteLine($"Connection: {e.PreviousState} -> {e.State}");
Method details
StartAsync
Task StartAsync(CancellationToken cancellationToken = default);
Finds the AR 51 server, connects, and starts every service stream (for example Skeletons). Completes once connected; returns at once if already started and connected.
cancellationToken was cancelled, or StopAsync was called, before the client connected.The client keeps trying until it connects, so with an unreachable server this waits until cancellationToken is cancelled. Cancelling only stops the wait: the client keeps connecting in the background until StopAsync or dispose.
// Wait at most 15 seconds for the server; the client keeps trying in the background.
using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(15));
try
{
await ar51.StartAsync(timeout.Token);
}
catch (OperationCanceledException)
{
Console.WriteLine("No AR 51 server found. Check the network or set AR51ClientOptions.Host.");
}
StopAsync
Task StopAsync(CancellationToken cancellationToken = default);
Stops every service stream, disconnects, and waits until everything is closed. The client can be started again. Calling it again, or before StartAsync, does nothing.
Running await foreach loops over a service's StreamAsync end normally, without an exception.
await ar51.StopAsync(); // stops every stream and disconnects; StartAsync can be called again
Related types
Small types used by this interface, documented here.
ConnectionState
enumpublic enum ConnectionState
The connection state of an IAR51Client.
| Value | Meaning |
|---|---|
Disconnected = 0 | Not connected: not started, stopped, or disposed. |
Connecting = 1 | Looking for the server or (re)connecting to it. |
Connected = 2 | Connected to the server. |
ConnectionStateChangedEventArgs
class · sealedpublic sealed class ConnectionStateChangedEventArgs : EventArgs
Data for IAR51Client.ConnectionStateChanged.
| Property | Type | Access | Description |
|---|---|---|---|
PreviousState | ConnectionState | get | The state before the change. |
State | ConnectionState | get | The new state. |
Constructor
public ConnectionStateChangedEventArgs(ConnectionState previousState, ConnectionState state);
Creates the event data.
See also
- Connecting guide — walkthrough with a complete, compiled sample
- Class index — every AR51.Net type
- Data conventions, threading and errors