Skip to main content

IAR51Client

interface IAsyncDisposable thread-safe
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.

How-to

This page is reference (facts only). For a walkthrough with a complete sample, see the Connecting guide.

Properties​

PropertyTypeAccessDescription
StateConnectionStategetThe current connection state.
ServerEndPointIPEndPoint?getThe address of the AR 51 server this client is connected to, or null while it is not connected.
SkeletonsISkeletonClientgetLive skeletons of the people the system tracks. Started and stopped together with this client; it can also be stopped and started on its own.
ObjectDetectionIObjectDetectionClientgetLive tracked objects, for example props. Started and stopped together with this client; it can also be stopped and started on its own.
ServersIServerClientgetThe AR 51 server machines: status, launch and quit the server program, start and stop tracking.
CamerasICameraClientgetThe cameras: list with calibration values, live preview, image settings and auto-tune.
CalibrationICalibrationClientgetCamera calibration and the tracked area (capture bounds).
RecordingIRecordingClientgetRecording of camera video and tracking data on the servers.
DevicesIDeviceClientgetThe apps and devices connected to the system: headsets, Unity and Unreal apps, phones and Mocap Studio.

Method summary​

→ Full descriptions in Method details below.

Events​

Standard .NET events (EventHandler<T>): subscribe with +=, unsubscribe with -=. They are raised on a background thread.

EventArgsRaised when
ConnectionStateChangedConnectionStateChangedEventArgsRaised when State changes. Raised on a background thread.
Example
ar51.ConnectionStateChanged += (_, e) =>
Console.WriteLine($"Connection: {e.PreviousState} -> {e.State}");

Method details​

StartAsync​

method
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.

Parameters
cancellationTokenCancellationTokenStops waiting. To limit the wait, pass a token with a timeout. Optional.
ReturnsTaskA task that completes when the client is connected.
Throws
OperationCanceledExceptioncancellationToken was cancelled, or StopAsync was called, before the client connected.
ObjectDisposedExceptionThe client was disposed.
note

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.

Example
// 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​

method
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.

Parameters
cancellationTokenCancellationTokenStops waiting for the shutdown to finish; the shutdown still completes. Optional.
ReturnsTaskA task that completes when everything is closed.
note

Running await foreach loops over a service's StreamAsync end normally, without an exception.

Example
await ar51.StopAsync(); // stops every stream and disconnects; StartAsync can be called again

Small types used by this interface, documented here.

ConnectionState​

enum
public enum ConnectionState

The connection state of an IAR51Client.

ValueMeaning
Disconnected = 0Not connected: not started, stopped, or disposed.
Connecting = 1Looking for the server or (re)connecting to it.
Connected = 2Connected to the server.

ConnectionStateChangedEventArgs​

class · sealed
public sealed class ConnectionStateChangedEventArgs : EventArgs

Data for IAR51Client.ConnectionStateChanged.

PropertyTypeAccessDescription
PreviousStateConnectionStategetThe state before the change.
StateConnectionStategetThe new state.
Constructor
public ConnectionStateChangedEventArgs(ConnectionState previousState, ConnectionState state);

Creates the event data.

See also​

Was this page helpful?