Share via


EndpointPair Class

Definition

Represents a pairing of local and remote host/service identifiers (host name or IP plus service name or port) used to initiate or describe a network connection.

public ref class EndpointPair sealed
/// [Windows.Foundation.Metadata.Activatable(Windows.Networking.IEndpointPairFactory, 65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class EndpointPair final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.Activatable(Windows.Networking.IEndpointPairFactory, 65536, "Windows.Foundation.UniversalApiContract")]
class EndpointPair final
[Windows.Foundation.Metadata.Activatable(typeof(Windows.Networking.IEndpointPairFactory), 65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class EndpointPair
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.Activatable(typeof(Windows.Networking.IEndpointPairFactory), 65536, "Windows.Foundation.UniversalApiContract")]
public sealed class EndpointPair
function EndpointPair(localHostName, localServiceName, remoteHostName, remoteServiceName)
Public NotInheritable Class EndpointPair
Inheritance
Object Platform::Object IInspectable EndpointPair
Attributes

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

Remarks

Purpose

Encapsulates the tuple of (local host, local service, remote host, remote service) used by higher-level networking APIs (e.g., sockets, Wi‑Fi Direct, connectivity helpers) to establish or describe a connection attempt.

Components

Role Members Notes
Local endpoint LocalHostName, LocalServiceName Either or both may be unspecified (null / empty) and resolved by the system
Remote endpoint RemoteHostName, RemoteServiceName Must normally identify the target host + service/port

Automatic resolution

  • If LocalHostName is null when a socket bind/connect starts, the system selects an appropriate local interface address.
  • If LocalServiceName is empty, an ephemeral (dynamic) port is allocated. Query the resulting bound socket properties after connect/bind to learn the chosen address/port.

Common usage

Scenario API pattern
Establish UDP / TCP socket Pass an EndpointPair to [DatagramSocket.ConnectAsync] or [StreamSocket.ConnectAsync]
Ordered connection attempts (Happy Eyeballs / multi-path) Use NetworkInformation.GetSortedEndpointPairs then iterate
Wi‑Fi Direct connection endpoints Retrieve list from WiFiDirectDevice.GetConnectionEndpointPairs

Best practices

  • Avoid hard-coding numeric ports where a well-known service name (e.g., "https") conveys intent and may map correctly on non-standard configurations.
  • Reuse a resolved local endpoint only while the underlying interface remains valid; interface changes (roam / suspend) can invalidate prior local addresses.
  • Prefer specifying the remote service name (string) instead of resolving it separately to a port number—lets the platform apply service-specific policies.
  • For dual-stack (IPv4/IPv6) targets, obtain a ranked list with GetSortedEndpointPairs and attempt in order rather than guessing.

Diagnostics

Log both remote and resolved local endpoint information (host + port) when capturing connection telemetry to accelerate troubleshooting (e.g., NAT / firewall issues).

Note

Ephemeral local ports are automatically recycled by the OS after the socket closes; do not attempt manual reservation beyond the socket lifetime.

Constructors

EndpointPair(HostName, String, HostName, String)

Creates a new EndpointPair object.

Properties

LocalHostName

Get or set the local hostname for the EndpointPair object.

LocalServiceName

Get or set the local service name for the EndpointPair object.

RemoteHostName

Get or set the remote hostname for the EndpointPair object.

RemoteServiceName

Get or set the remote service name for the EndpointPair object.

Applies to

See also