# UNetworkUtils

<Badge tone="type">UCLASS · UObject</Badge> <Badge>static helpers</Badge>

```cpp
UCLASS()
class AR51SDK_API UNetworkUtils : public UObject
```

**Inherits:** [`UObject`](https://dev.epicgames.com/documentation/en-us/unreal-engine/API/Runtime/CoreUObject/UObject/UObject) *(Unreal Engine)*

A stateless utility class of **static** networking helpers. You never instantiate it — call its functions directly (`UNetworkUtils::GetLocalIp()`), or use the pure/callable Blueprint nodes. Handy for advertising the device's local IP and for picking a free port before opening a connection or stream. Defined in `Public/Utilities/NetworkUtils.h`.

:::note
This area exposes platform/networking helpers only — no positions, lengths, or angles — so the AR 51 (meters) ↔ Unreal (cm/degrees) unit conversion does not apply here.
:::

## Method summary

**Static**

| Method | Returns | |
|---|---|---|
| [`GetLocalIp`](#getlocalip) | `FString` | <Badge tone="accent">BlueprintPure</Badge> |
| [`GetAvailablePort`](#getavailableport) | `bool` | <Badge tone="accent">BlueprintCallable</Badge> |
| [`GetLocalAddresses`](#getlocaladdresses) | [`TArray<TSharedPtr<FInternetAddr>>`](https://dev.epicgames.com/documentation/en-us/unreal-engine/API/Runtime/Sockets/FInternetAddr) | <Badge>C++ only</Badge> |

→ Full descriptions in [Method details](#method-details) below.

## Method details

### GetLocalIp

<ApiBody kind="method" tags="static, BlueprintPure">

```cpp
static FString GetLocalIp();
```

The device's local IP address as a string, or an empty string if no valid address can be obtained. Exposed as a pure Blueprint node (no exec pins).

<Returns type="FString">the local IP as `"x.x.x.x"`, or `""` if none is available</Returns>

</ApiBody>

### GetAvailablePort

<ApiBody kind="method" tags="static, BlueprintCallable">

```cpp
static bool GetAvailablePort(int32 StartPort, const TSet<int32>& ExcludedPorts, int32& OutPort);
```

Scans upward from `StartPort` for the first free network port that is **not** in `ExcludedPorts`, writes it to `OutPort`, and returns `true`. On failure `OutPort` is set to `-1` and the function returns `false`. Use it to pick a free port before opening a connection or stream.

<Params>
<Param name="StartPort" type="int32">the port to start scanning from (inclusive)</Param>
<Param name="ExcludedPorts" type="TSet<int32>">ports to skip even if free (e.g. ports you already reserved)</Param>
<Param name="OutPort" type="int32&">out — the first free port found, or `-1` on failure</Param>
</Params>

<Returns type="bool">`true` and a valid `OutPort` if a free port was found; `false` and `OutPort == -1` otherwise</Returns>

<Example inferred>

```cpp
// Reserve a free port at/above 50000, skipping a couple we plan to use elsewhere.
int32 Port = -1;
const TSet<int32> Reserved = { 50051, 50052 };
if (UNetworkUtils::GetAvailablePort(50000, Reserved, Port))
{
    const FString Endpoint = FString::Printf(TEXT("%s:%d"), *UNetworkUtils::GetLocalIp(), Port);
    UE_LOG(LogTemp, Log, TEXT("Listening on %s"), *Endpoint);
}
else
{
    UE_LOG(LogTemp, Warning, TEXT("No free port available from 50000"));
}
```

</Example>

</ApiBody>

### GetLocalAddresses

<ApiBody kind="method" tags="static, C++ only">

```cpp
static TArray<TSharedPtr<FInternetAddr>> GetLocalAddresses();
```

All local network addresses for the device, or an empty array if the socket subsystem is unavailable or none are found. This is the lower-level counterpart to [`GetLocalIp`](#getlocalip) — use it from C++ when you need the full address list rather than a single string. Not a `UFUNCTION`, so it is **not** available in Blueprint.

<Returns type="TArray<TSharedPtr<FInternetAddr>>" typeHref="https://dev.epicgames.com/documentation/en-us/unreal-engine/API/Runtime/Sockets/FInternetAddr">every local address; empty if the socket subsystem is unavailable</Returns>

</ApiBody>

## See also

- [`AAR51SDK`](/docs/sdk-api/unreal-api/classes/aar51sdk) — connection entry point; its `ServiceLocalIPAddress` / `ServicesPort` properties pair with these helpers
- [`UnrealThread`](/docs/sdk-api/unreal-api/classes/unrealthread) — the other public C++ utility in this area (game-thread dispatcher)
- [Utilities & Platform](/docs/sdk-api/unreal-api/utilities-platform) — platform enum, networking, threading, logging, singletons
- [Class index](/docs/sdk-api/unreal-api/classes) — all Unreal SDK types
