Skip to main content

UNetworkUtils

UCLASS · UObject static helpers
UCLASS()
class AR51SDK_API UNetworkUtils : public UObject

Inherits: 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

MethodReturns
GetLocalIpFStringBlueprintPure
GetAvailablePortboolBlueprintCallable
GetLocalAddressesTArray<TSharedPtr<FInternetAddr>>C++ only

→ Full descriptions in Method details below.

Method details

GetLocalIp

methodstaticBlueprintPure
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).

ReturnsFStringthe local IP as "x.x.x.x", or "" if none is available

GetAvailablePort

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

Parameters
StartPortint32the port to start scanning from (inclusive)
ExcludedPortsTSet<int32>ports to skip even if free (e.g. ports you already reserved)
OutPortint32&out — the first free port found, or -1 on failure
Returnsbooltrue and a valid OutPort if a free port was found; false and OutPort == -1 otherwise
Exampleinferred
// 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"));
}

GetLocalAddresses

methodstaticC++ only
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 — 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.

ReturnsTArray<TSharedPtr<FInternetAddr>>every local address; empty if the socket subsystem is unavailable

See also

  • AAR51SDK — connection entry point; its ServiceLocalIPAddress / ServicesPort properties pair with these helpers
  • UnrealThread — the other public C++ utility in this area (game-thread dispatcher)
  • Utilities & Platform — platform enum, networking, threading, logging, singletons
  • Class index — all Unreal SDK types
Was this page helpful?