Share via


DatagramSocket.BindServiceNameAsync Method

Definition

Overloads

BindServiceNameAsync(String)

Starts a bind operation on a DatagramSocket to a local service name.

BindServiceNameAsync(String, NetworkAdapter)

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

BindServiceNameAsync(String)

Starts a bind operation on a DatagramSocket to a local service name.

public:
 virtual IAsyncAction ^ BindServiceNameAsync(Platform::String ^ localServiceName) = BindServiceNameAsync;
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncAction BindServiceNameAsync(winrt::hstring const& localServiceName);
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncAction BindServiceNameAsync(string localServiceName);
function bindServiceNameAsync(localServiceName)
Public Function BindServiceNameAsync (localServiceName As String) As IAsyncAction

Parameters

localServiceName
String

Platform::String

winrt::hstring

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

Returns

An asynchronous bind operation on a DatagramSocket object.

Attributes

Windows requirements

App capabilities
ID_CAP_NETWORKING [Windows Phone] internetClientServer privateNetworkClientServer

Remarks

The BindServiceNameAsync method binds to the local IP addresses of all network interfaces on the local computer on the local service name or UDP port specified in the localServiceName parameter. If the localServiceName parameter is an empty string, the system will select the local UDP port on which to bind.

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.

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. 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.

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

See also

Applies to

BindServiceNameAsync(String, NetworkAdapter)

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

public:
 virtual IAsyncAction ^ BindServiceNameAsync(Platform::String ^ localServiceName, NetworkAdapter ^ adapter) = BindServiceNameAsync;
/// [Windows.Foundation.Metadata.Overload("BindServiceNameAndAdapterAsync")]
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncAction BindServiceNameAsync(winrt::hstring const& localServiceName, NetworkAdapter const& adapter);
[Windows.Foundation.Metadata.Overload("BindServiceNameAndAdapterAsync")]
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncAction BindServiceNameAsync(string localServiceName, NetworkAdapter adapter);
function bindServiceNameAsync(localServiceName, adapter)
Public Function BindServiceNameAsync (localServiceName As String, adapter As NetworkAdapter) As IAsyncAction

Parameters

localServiceName
String

Platform::String

winrt::hstring

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

adapter
NetworkAdapter

The network adapter on which to bind the DatagramSocket object.

Returns

An asynchronous bind operation on a DatagramSocket object.

Attributes

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.

See also

Applies to