> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XNetworkingQueryPreferredLocalUdpMultiplayerPortAsync

> XNetworkingQueryPreferredLocalUdpMultiplayerPortAsync

Gets the preferred local UDP port to use for multiplayer traffic asynchronously.

## Syntax

```cpp theme={null}
HRESULT XNetworkingQueryPreferredLocalUdpMultiplayerPortAsync(
         XAsyncBlock* asyncBlock
)
```

### Parameters

*asyncBlock*   \_Inout\_\
Type: [XAsyncBlock](https://docs.xbox.com/reference/system/xasync/structs/xasyncblock.md)\*

A pointer to the [XAsyncBlock](https://docs.xbox.com/reference/system/xasync/structs/xasyncblock.md) that is passed to [XAsyncRun](https://docs.xbox.com/reference/system/xasync/functions/xasyncrun.md).

### Return value

Type: HRESULT

HRESULT success or error code.

## Remarks

Use the returned preferred local UDP multiplayer port in subsequent [socket bind](https://learn.microsoft.com/windows/desktop/api/winsock/nf-winsock-bind) operations. The port is targeted specifically at multiplayer real-time title networking flows and is meaningful for UDP traffic only, not for TCP or HTTP traffic.

To listen for changes in the preferred local UDP multiplayer, call [XNetworkingRegisterPreferredLocalUdpMultiplayerPortChanged](https://docs.xbox.com/reference/networking/xnetworking/functions/xnetworkingregisterpreferredlocaludpmultiplayerportchanged.md).

For a description of how the local UDP multiplayer port works, see the Remarks section of the synchronous version of [XNetworkingQueryPreferredLocalUdpMultiplayerPort](https://docs.xbox.com/reference/networking/xnetworking/functions/xnetworkingquerypreferredlocaludpmultiplayerport.md).

This method interrogates the local state within the calling process and returns quickly, so it is safe to call from time-sensitive contexts.

## Requirements

**Header:** XNetworking.h

**Library:** xgameruntime.lib

**Supported platforms:** Windows, XBOX One family consoles and XBOX Series consoles

## Conceptual documentation

* [Preferred UDP multiplayer port](https://docs.xbox.com/build/console-features/networking/game-mesh/preferred-local-udp-multiplayer-port-networking.md)

## See also

[Preferred local UDP multiplayer port](https://docs.xbox.com/build/console-features/networking/game-mesh/preferred-local-udp-multiplayer-port-networking.md)\
[Windows Sockets (Winsock)](https://learn.microsoft.com/windows/desktop/WinSock/windows-sockets-start-page-2)\
[Microsoft Azure PlayFab Party](https://docs.xbox.com/build/console-features/networking/game-mesh/playfab-party-intro-networking.md)\
[XNetworking](https://docs.xbox.com/reference/networking/xnetworking/xnetworking_members.md)


## Related topics

- [XNetworkingQueryPreferredLocalUdpMultiplayerPortAsyncResult](https://docs.xbox.com/reference/networking/xnetworking/functions/xnetworkingquerypreferredlocaludpmultiplayerportasyncresult.md)
- [Preferred UDP multiplayer port](https://docs.xbox.com/build/console-features/networking/game-mesh/preferred-local-udp-multiplayer-port-networking.md)
- [XNetworking (API contents)](https://docs.xbox.com/reference/networking/xnetworking/xnetworking_members.md)
- [Using C# wrappers for GDK APIs in your Unity project](https://docs.xbox.com/build/gdk-and-engines/unity/unity-api-wrappers.md)
- [XNetworkingQueryPreferredLocalUdpMultiplayerPort](https://docs.xbox.com/reference/networking/xnetworking/functions/xnetworkingquerypreferredlocaludpmultiplayerport.md)
