SkeletonClient
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.
This page is reference (facts only). For a walkthrough with a complete sample, see the Skeletons guide.
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
| Property | Type | Access | Description |
|---|---|---|---|
IsAvailable | bool | get | true when the skeleton service's address is known (always, for a standalone SkeletonClient). Implements ISkeletonClient.IsAvailable. |
Method summary
| Method | Returns | |
|---|---|---|
Constructor | — | constructor |
StartAsync | Task | implements |
StopAsync | Task | implements |
StreamAsync | IAsyncEnumerable<Skeleton> | implements |
DisposeAsync | ValueTask |
→ 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 |
|---|---|---|
SkeletonReceived | SkeletonEventArgs | Raised 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
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.
host is empty.port is not between 1 and 65535.AR 51 service ports are not fixed. Prefer IAR51Client.Skeletons, which finds the service for you.
StartAsync
public Task StartAsync(CancellationToken cancellationToken = default);
Starts receiving skeletons into SkeletonReceived. Returns at once; calling it again does nothing.
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
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.
StreamAsync loops end normally, without an exception, after the skeleton they are handling. Loops started after this call are not affected.
StreamAsync
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.
cancellationToken was cancelled.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
public ValueTask DisposeAsync();
Stops receiving, closes every stream and, for a standalone client, its connection. Calling it again does nothing.
See also
- Skeletons guide — walkthrough with a complete, compiled sample
- Class index — every AR51.Net type
- Data conventions, threading and errors