DatagramSocket.BindEndpointAsync(HostName, String) Method

Definition

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

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

Parameters

localHostName
HostName

The local hostname or IP address on which to bind the DatagramSocket object.

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 BindEndpointAsync method binds the DatagramSocket to the local hostname or IP address specified in the localHostName parameter and the local service name or UDP port number address specified in the localServiceName parameter. If the localHostName parameter is null, the system will select the local IP address on which to bind. 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 BindEndpointAsync method will fail if another app using UDP (for example, another DatagramSocket) has already been bound to the local IP address and UDP port specified in the localHostName and localServiceName parameters.

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 if the socket isn't already bound. Writing to a stream returned by one of the GetOutputStreamAsync methods will also result in a bind operation.

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

Applies to

See also