DatagramSocket.BindServiceNameAsync(String, NetworkAdapter) | bindServiceNameAsync(String, NetworkAdapter) method
Starts a bind operation on a DatagramSocket to a local service name and specific network interface.
datagramSocket.bindServiceNameAsync(localServiceName, adapter).done( /* Your success and error handlers */ );
The local service name or UDP port on which to bind the DatagramSocket object.
The network adapter on which to bind the DatagramSocket object.
An asynchronous bind operation on a DatagramSocket object.
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 DatagramSocket is used only to send data.
- The DatagramSocket is used to send data to and receive data from a single endpoint.
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.
Minimum supported client
Minimum supported server
|Windows Server 2012 R2|