Socket. Bind Endpoint Async(HostName, String) Method
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
The local service name or UDP port on which to bind the DatagramSocket object.
An asynchronous bind operation on a DatagramSocket object.
ID_CAP_NETWORKING [Windows Phone] internetClientServer privateNetworkClientServer
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:
- The DatagramSocket is used only to send data.
- The DatagramSocket is used to send data to and receive data from a single endpoint.