Skip to main content

SkeletonClient

class · sealed IAsyncDisposable thread-safe
namespace AR51.Net;

public sealed class SkeletonClient : ISkeletonClient, IAsyncDisposable

Implements: ISkeletonClient · IAsyncDisposable

Dispose it with await using (or DisposeAsync): this stops every stream and closes every connection. Calling it again does nothing.

Receives live skeletons from the AR 51 skeleton service. Get one from IAR51Client.Skeletons (recommended: the server is found for you), or create one on its own with the service's address.

How-to

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

Example
await using var skeletons = new SkeletonClient("192.168.1.20", 1503);
skeletons.SkeletonReceived += (_, e) => Console.WriteLine(e.Skeleton.GetPosition(Joint.MidHip));
await skeletons.StartAsync();

Properties​

PropertyTypeAccessDescription
IsAvailableboolgettrue when the skeleton service's address is known (always, for a standalone SkeletonClient). Implements ISkeletonClient.IsAvailable.

Method summary​

MethodReturns
Constructor—constructor
StartAsyncTaskimplements
StopAsyncTaskimplements
StreamAsyncIAsyncEnumerable<Skeleton>implements
DisposeAsyncValueTask

→ 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
SkeletonReceivedSkeletonEventArgsRaised for every skeleton received while started, on a background thread. Keep handlers short: they run on the receiving thread. An exception thrown by a handler is logged and does not stop the others or the stream. Implements ISkeletonClient.SkeletonReceived.

Method details​

Constructor​

method
public SkeletonClient(string host, int port, ILoggerFactory? loggerFactory = null);

Creates a standalone client for the skeleton service at host:port. Call StartAsync to begin receiving.

Parameters
hoststringHost name or IP address of the AR 51 server running the skeleton service.
portintPort of the skeleton service.
loggerFactoryILoggerFactory?Receives the client's diagnostic log. null disables logging. Optional.
Throws
ArgumentExceptionhost is empty.
ArgumentOutOfRangeExceptionport is not between 1 and 65535.
note

AR 51 service ports are not fixed. Prefer IAR51Client.Skeletons, which finds the service for you.

StartAsync​

methodimplements ISkeletonClient
public Task StartAsync(CancellationToken cancellationToken = default);

Starts receiving skeletons into SkeletonReceived. Returns at once; calling it again does nothing.

Parameters
cancellationTokenCancellationTokenIgnored. Optional.
ReturnsTaskA completed task.
Throws
ObjectDisposedExceptionThe client was disposed.
note

Receiving begins as soon as the skeleton service is reachable, and resumes by itself after the service restarts or the network drops, until StopAsync or dispose.

StopAsync​

methodimplements ISkeletonClient
public Task StopAsync(CancellationToken cancellationToken = default);

Stops receiving skeletons: stops SkeletonReceived, ends every StreamAsync loop running now, and waits until the event stream is closed. Calling it again does nothing.

Parameters
cancellationTokenCancellationTokenStops waiting for the stream to close; the stream still closes. Optional.
ReturnsTaskA task that completes when the event stream is closed.
note

StreamAsync loops end normally, without an exception, after the skeleton they are handling. Loops started after this call are not affected.

StreamAsync​

methodimplements ISkeletonClient
public IAsyncEnumerable<Skeleton> StreamAsync([EnumeratorCancellation] CancellationToken cancellationToken = default);

Streams skeletons until StopAsync is called (the loop ends normally), cancellationToken is cancelled, or the connection drops. Works without StartAsync.

Parameters
cancellationTokenCancellationTokenStops the stream. Optional.
ReturnsIAsyncEnumerable<Skeleton>Skeletons in the order they arrive.
Throws
AR51ExceptionThe skeleton service is not available, or the stream failed.
OperationCanceledExceptioncancellationToken was cancelled.
ObjectDisposedExceptionThe client was disposed.
note

Each call opens its own stream, which closes when the loop ends. Unlike SkeletonReceived, it does not reconnect: start a new loop after an AR51Exception.

DisposeAsync​

method
public ValueTask DisposeAsync();

Stops receiving, closes every stream and, for a standalone client, its connection. Calling it again does nothing.

ReturnsValueTaskA task that completes when everything is closed.

See also​

Was this page helpful?