# Install AR51.Net and Run Your First Program

Add **AR51.Net** to a .NET project, connect to your AR 51 system, and print the people it tracks — in about five minutes. When you finish, you'll have a console app that prints every tracked person's hip position, live.

## Before you start

You need:

- The **.NET 8 SDK** or later.
- A **running AR 51 system with tracking started**, reachable from your computer over the local network (same subnet for automatic discovery).
- **Someone in the capture area** — skeletons arrive only while a person is tracked.
- Outgoing **UDP 1500** and **TCP** to the AR 51 machines allowed by your firewall (see the [checklist](#first-run-checklist)).

## 1. Create a project

```bash
dotnet new console -n MyAr51App
cd MyAr51App
```

## 2. Add the AR51.Net package

```bash
dotnet add package AR51.Net
```

That's it — the package and its dependencies come from nuget.org. There are no native libraries to install. Adding the package means you accept the [AR51.Net license](/docs/csharp-api/overview/#license); Visual Studio shows it for you to accept.

<details>
<summary>Can't use nuget.org? Install from the download page instead</summary>

AR51.Net is also on the AR 51 [download page](/download/).

1. Download **AR51.Net (3.0.3.2R)** — the file `AR51.Net.3.0.302.nupkg`.
2. In your project folder, create a folder named `packages` and put the file in it.
3. Next to your project file, add a file named `nuget.config`:

   ```xml title="nuget.config"
   <?xml version="1.0" encoding="utf-8"?>
   <configuration>
     <packageSources>
       <clear />
       <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
       <add key="ar51" value="packages" />
     </packageSources>
     <packageSourceMapping>
       <packageSource key="ar51">
         <package pattern="AR51.*" />
       </packageSource>
       <packageSource key="nuget.org">
         <package pattern="*" />
       </packageSource>
     </packageSourceMapping>
   </configuration>
   ```

4. Add the package:

   ```bash
   dotnet add package AR51.Net
   ```

The `nuget.config` makes `AR51.*` packages come **only** from your `packages` folder. AR51.Net's few dependencies (`Google.Protobuf`, `Grpc.Net.Client`, `Microsoft.Extensions.Logging.Abstractions`) still come from nuget.org; on a computer with no internet at all, those must already be in its package cache. To update later, put the new `.nupkg` in `packages` and change the version in your project file.

</details>

Your project file then looks like this:

```xml title="MyAr51App.csproj"
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="AR51.Net" Version="3.0.302" />
  </ItemGroup>

</Project>
```

`TargetFramework` is your SDK's version — `net8.0` on the .NET 8 SDK, `net10.0` on .NET 10. AR51.Net supports both.

## 3. Write the program

Replace `Program.cs` with:

{/* SAMPLE:01-quickstart — generated from the ar51-net-samples repo; edit there */}
```csharp title="Program.cs"
// Connect to the AR 51 system and print the skeletons that arrive. Press Ctrl+C to quit.
using AR51.Net;

await using IAR51Client ar51 = AR51Client.Create();   // finds the AR 51 server on the local network

ar51.Skeletons.SkeletonReceived += (_, e) =>
{
    Skeleton skeleton = e.Skeleton;
    Console.WriteLine($"{skeleton.Id}: hips at {skeleton.GetPosition(Joint.MidHip)} m");
};

Console.WriteLine("Looking for the AR 51 server...");
await ar51.StartAsync();
Console.WriteLine($"Connected to {ar51.ServerEndPoint}. Press Ctrl+C to quit.");

using var quit = new CancellationTokenSource();
Console.CancelKeyPress += (_, e) => { e.Cancel = true; quit.Cancel(); };
try { await Task.Delay(Timeout.Infinite, quit.Token); } catch (OperationCanceledException) { }
```

[View this sample on Bitbucket](https://bitbucket.org/ar51/ar51-net-samples/src/main/01-quickstart/) — clone the [samples repository](https://bitbucket.org/ar51/ar51-net-samples) to run it.
{/* /SAMPLE */}

`AR51Client.Create()` makes a client that **finds the AR 51 server on your local network by itself**. `StartAsync` returns once it's connected; from then on `SkeletonReceived` fires for every tracked person, many times per second.

## 4. Run it

```bash
dotnet run
```

The program finds the server and connects — this is a real run on Linux:

```text
Looking for the AR 51 server...
Connected to 192.168.0.199:1501. Press Ctrl+C to quit.
```

The address is your AR 51 server's. Then, while someone is in the tracked area, one line per tracked person arrives many times per second, in the form `<id>: hips at <X, Y, Z> m`. The first lines can appear just before `Connected to …`. If no skeleton lines arrive, nobody is being tracked yet — see the checklist below. Press **Ctrl+C** to quit.

:::tip[No live system? Use the emulator]
The [Mocap Studio emulator](/docs/mocap-studio/emulator/) replays recorded captures and streams them as if a live system were running, so you can develop and test without cameras or people in the area. It streams **skeletons and objects only**: servers, cameras, calibration, recording and devices aren't available.
:::

## First-run checklist

If nothing arrives, check these in order:

1. **The AR 51 system is running and tracking** — check in Mocap Studio, or list the machines with [`ar51.Servers`](/docs/csharp-api/servers-and-devices/).
2. **Same network.** Your computer is on the same local network (subnet) as the AR 51 machines. If it isn't, connect to a [fixed host](/docs/csharp-api/connecting/#connect-to-a-fixed-host).
3. **Firewall.** Your computer allows outgoing **UDP on port 1500** (discovery) and **TCP** to the AR 51 machines (port **1501** and the ports the system assigns to its services).
4. **Someone is in view.** Skeletons arrive only while a person is in the tracked area.
5. **One client.** Create one `IAR51Client` for the whole application and dispose it at the end (`await using`).

Still stuck? See [Troubleshooting](/docs/csharp-api/troubleshooting/).

## Get all the samples

Every guide ends with a complete program. They're all in the [AR51.Net samples repository](https://bitbucket.org/ar51/ar51-net-samples), ready to run — clone it and `dotnet run` any of them. It also includes a full [web dashboard](/docs/csharp-api/web-dashboard/) sample.

```bash
git clone https://bitbucket.org/ar51/ar51-net-samples.git
```

## Next steps

- [Connecting](/docs/csharp-api/connecting/) — a fixed host, connection state, logging, clean shutdown
- [Skeletons](/docs/csharp-api/skeletons/) — joints, confidence, hands and identity
- [API reference](/docs/sdk-api/csharp-api/)
