Skip to main content
DatagramSocketInformation.LocalPort | localPort property

The local service name or UDP port number associated with a DatagramSocket.

Syntax


var localPort = datagramSocketInformation.localPort;

public string LocalPort { get; }

Public ReadOnly Property LocalPort As String

public:
property String^ LocalPort { 
   String^ get();
}

Property value

Type: String [JavaScript] | System.String [.NET] | Platform::String [C++]

The local service name or UDP port number.

Remarks

The LocalPort property represents the local service name or UDP port number bound to the DatagramSocket object.

An app can set the local service name or UDP port number to use by calling the BindEndpointAsync , BindServiceNameAsync, ConnectAsync(EndpointPair) , or GetOutputStreamAsync(EndpointPair) methods on the DatagramSocket. The bind or connect operation will bind the socket to the specific local IP address and local UDP port number. After the bind or connect operation completes, LocalAddress property contains the IP address and the LocalPort property contains the local UDP port number that the local hostname and service name resolved to.

If the local service name or UDP port number passed to the BindEndpointAsync , BindServiceNameAsync, ConnectAsync(EndpointPair) , or GetOutputStreamAsync(EndpointPair) methods is an empty string or the ConnectAsync(HostName, String) or GetOutputStreamAsync(HostName, String) method is called, the system will determine the local UDP port to bind to the DatagramSocket object.

Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

Windows.Networking.Sockets
Windows::Networking::Sockets [C++]

Metadata

Windows.Foundation.UniversalApiContract.winmd

Capabilities

Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8

Namespace

Windows.Networking.Sockets
Windows::Networking::Sockets [C++]

Metadata

Windows.winmd

Capabilities

ID_CAP_NETWORKING [Windows Phone]

See also

Other resources
How to use advanced socket controls (HTML)
How to use advanced socket controls (XAML)
Reference
DatagramSocket
DatagramSocket.BindEndpointAsync
DatagramSocket.BindServiceNameAsync
DatagramSocket.ConnectAsync
DatagramSocket.GetOutputStreamAsync
DatagramSocketInformation
LocalAddress
RemoteAddress
RemotePort