DatagramSocket.BindServiceNameAsync(String, NetworkAdapter) | bindServiceNameAsync(String, NetworkAdapter) method

Applies to Windows and Windows Phone

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

Syntax


datagramSocket.bindServiceNameAsync(localServiceName, adapter).done( /* Your success and error handlers */ );

Parameters

localServiceName

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

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

adapter

Type: NetworkAdapter

The network adapter on which to bind the DatagramSocket object.

Return value

Type: IAsyncAction

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.

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.

Requirements

Minimum supported client

Windows 8.1

Minimum supported server

Windows Server 2012 R2

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

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

Metadata

Windows.winmd

See also

DatagramSocket
BindServiceNameAsync(String)
BindEndpointAsync
DatagramSocketInformation

 

 

Show:
© 2014 Microsoft