StreamSocketListener.BindServiceNameAsync(String, SocketProtectionLevel, NetworkAdapter) | bindServiceNameAsync(String, SocketProtectionLevel, NetworkAdapter) method

Applies to Windows and Windows Phone

Starts a socket bind operation on a StreamSocketListener to a local service name on a specified network adapter with a specified SocketProtectionLevel to set on any bound sockets.

Syntax


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

Parameters

localServiceName

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

The local service name or TCP port on which to bind the StreamSocketListener object. For Bluetooth RFCOMM, this parameter is the Bluetooth Service ID.

protectionLevel

Type: SocketProtectionLevel

The protection level for encryption to set on any bound sockets.

adapter

Type: NetworkAdapter

The network adapter on which to bind the StreamSocketListener object.

Return value

Type: IAsyncAction

The asynchronous bind operation on a StreamSocketListener object.

Remarks

The BindServiceNameAsync(String, SocketProtectionLevel, NetworkAdapter) method binds to the local service name or TCP port specified in the localServiceName parameter on the network adapter specified in the adapter parameter on the local computer. For Bluetooth RFCOMM, this method binds to the Bluetooth Service ID specified in the localServiceName parameter if the adapter parameter is null. A Bluetooth Service ID must be supplied to bind for Bluetooth. If a network adapter is specified in the adapter parameter and the localServiceName parameter contains a Bluetooth Service ID, then this method will fail.

This method sets the protection level for encryption on any bound sockets to the protectionLevel parameter.

If the localServiceName parameter is an empty string, then the system will select the local TCP port on which to bind. If the adapter parameter is null for a TCP socket bind, an error will occur.

The name resolution mechanism used by the BindServiceNameAsync(String, SocketProtectionLevel, NetworkAdapter) method is limited to the specified interface for the domain name system (DNS) namespace.

The BindServiceNameAsync(String, SocketProtectionLevel, NetworkAdapter) method will fail if another app (another StreamSocketListener, for example) has already been bound to the local TCP port specified in the localServiceName parameter on the network adapter specified in the adapter parameter. For Bluetooth, this method will fail if another app (another StreamSocketListener, for example) has already been bound to the Bluetooth Service ID specified in the localServiceName parameter.

Using the specified network adapter is on a best-effort basis. A system with adapters configured in weak-host or forwarding modes may use an adapter other than the specified adapter.

The protectionLevel parameter must be set to PlainSocket for all sockets except those used over Bluetooth. When the socket is to be used over Bluetooth, the protectionLevel parameter can be set to PlainSocket, BluetoothEncryptionAllowNullAuthentication, or BluetoothEncryptionWithAuthentication. For more information, see the SocketProtectionLevel enumeration.

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

BindServiceNameAsync(String)
BindServiceNameAsync(String, SocketProtectionLevel)
SocketProtectionLevel
StreamSocketListener
StreamSocketListenerInformation

 

 

Show:
© 2014 Microsoft