Skip to content

Latest commit

 

History

History
46 lines (30 loc) · 3.57 KB

datagramsocket_bindservicenameasync_440542334.md

File metadata and controls

46 lines (30 loc) · 3.57 KB
-api-id -api-type
M:Windows.Networking.Sockets.DatagramSocket.BindServiceNameAsync(System.String,Windows.Networking.Connectivity.NetworkAdapter)
winrt method

Windows.Networking.Sockets.DatagramSocket.BindServiceNameAsync

-description

Starts a bind operation on a DatagramSocket to a local service name and specific network interface.

-parameters

-param localServiceName

The local service name or UDP port on which to bind the DatagramSocket object.

-param adapter

The network adapter on which to bind the DatagramSocket object.

-returns

An asynchronous bind operation on a DatagramSocket object.

-remarks

The [BindServiceNameAsync(String, NetworkAdapter) method binds to a network interface specified in the adapter parameter and the local service name or UDP port specified in the localServiceName parameter on the local computer. If the localServiceName parameter is an empty string, the system will select the local UDP port on which to bind. If the adapter parameter is null, an error will occur.

The name resolution mechanism used by the [BindServiceNameAsync(String, NetworkAdapter) method is limited to the specified interface for the domain name system (DNS) namespace.

Unless you've used the DatagramSocketControl.MulticastOnly property, the BindServiceNameAsync method will fail if another app using UDP (another DatagramSocket, for example) has already been bound to the local UDP port specified in the localServiceName parameter on the same network interface.

Binding is essential for receiving data from any remote endpoint on a DatagramSocket, and is commonly done after a socket is created and the MessageReceived event has been set. The BindServiceNameAsync or BindEndpointAsync method is used to bind a DatagramSocket to a local service name or UDP port. The ConnectAsync methods will also result in a bind operation, but can't be limited to a specific network adapter. Writing to a stream returned by one of the GetOutputStreamAsync methods will also result in a bind operation if the socket isn't already bound, but can't be limited to a specific network adapter.

The BindServiceNameAsync and BindEndpointAsync methods are not needed in the following cases:

If the [BindServiceNameAsync(String, NetworkAdapter) method is used, the bind operation will limit incoming and outgoing multicast and unicast packets to the specified adapter.

Using the specified network adapter is on a best-effort basis. Among other configuration, systems with adapters configured in weak-host or forwarding modes may use an adapter other than the specified adapter.

-examples

-see-also

BindServiceNameAsync(String), BindEndpointAsync, DatagramSocketInformation