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

# XNetworkingQueryPreferredLocalUdpMultiplayerPort

> XNetworkingQueryPreferredLocalUdpMultiplayerPort

# XNetworkingQueryPreferredLocalUdpMultiplayerPort

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

## Syntax

```cpp theme={null}
HRESULT XNetworkingQueryPreferredLocalUdpMultiplayerPort(
         uint16_t* preferredLocalUdpMultiplayerPort
)
```

### Parameters

*preferredLocalUdpMultiplayerPort*   \_Out\_\
Type: uint16\_t\*

Pointer to the User Datagram Protocol (UDP) port number (in host endian format) that is the preferred local UDP multiplayer port.

### Return value

Type: HRESULT

HRESULT success or error code.

## Remarks

<Note>This function isn't safe to call on a time-sensitive thread. For more information, see [Time-sensitive threads](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads).</Note>

The returned preferred local UDP multiplayer port is the local port to be used in a subsequent [socket bind](https://learn.microsoft.com/windows/desktop/api/winsock/nf-winsock-bind) operation as opposed to the public port that remote devices might use to connect to the local device. It is meaningful only for UDP traffic rather than TCP or HTTP traffic because it is targeted specifically at multiplayer real-time title networking flows.

This port defaults to UDP 3074, but there are both automatic fallbacks when the port is determined not to be suitable for gaming traffic and a manual override that users can set through the XBOX network settings troubleshooter. The network behavior for this port is used to drive the user-visible NAT type of strict, moderate, and open. The port is used by XBOX Party Chat, the XBOX network troubleshooter, online XBOX Live troubleshooting documentation, and CSS troubleshooting flows and is often manually configured in home routers by users.

The returned port will already be configured in the user's home router via UPnP to allow inbound and outbound packets.

The port should be treated just like every other port and should be used in conjunction with the [Windows Sockets (Winsock)](https://learn.microsoft.com/windows/desktop/WinSock/windows-sockets-start-page-2) APIs. The title should bind to both IPv4 and IPv6 on this port or use a dual-stack socket and should bind to the `INADDR_ANY`/`in6addr_any` address.

<Note>The port is returned from this function in host endian order. The `sockaddr_in::sin_port` and `sockaddr_in6::sin6_port` fields are both in network endian order. Use the [htons](https://learn.microsoft.com/windows/desktop/api/winsock/nf-winsock-htons) function to convert the endianness of the returned port when passing it to the bind function.</Note>

The returned port is not guaranteed to be able to be used to establish a successful socket connection with the desired server or peers. Any normal title retry and fallback logic should be performed.

The title is expected to provide a security layer and any necessary Network Address Translation (NAT) detection and traversal implementations that it might require.

Titles are strongly recommended to use this port for their main game traffic socket flow for the best chance at having a successful connection. The [Microsoft Azure PlayFab Party](/build/console-features/networking/game-mesh/playfab-party-intro-networking) library defaults to using this port. Unless you explicitly configure the PlayFab Party library to use a different port, do not bind directly to the preferred local UDP multiplayer port.

## Requirements

**Header:** XNetworking.h

**Library:** xgameruntime.lib

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

## Conceptual documentation

* [Preferred UDP multiplayer port](/build/console-features/networking/game-mesh/preferred-local-udp-multiplayer-port-networking)
* [Time-sensitive threads](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)

## See also

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


## Related topics

- [XNetworkingQueryPreferredLocalUdpMultiplayerPortAsync](/reference/networking/xnetworking/functions/xnetworkingquerypreferredlocaludpmultiplayerportasync.md)
- [Preferred local UDP multiplayer port networking APIs](/build/console-features/networking/game-mesh/preferred-local-udp-multiplayer-port-networking.md)
- [XNetworkingUnregisterPreferredLocalUdpMultiplayerPortChanged](/reference/networking/xnetworking/functions/xnetworkingunregisterpreferredlocaludpmultiplayerportchanged.md)
- [XNetworking](/reference/networking/xnetworking/xnetworking_members.md)
- [Unity C# API wrappers for the GDK](/build/gdk-and-engines/unity/unity-api-wrappers.md)
