Skip to main content
StreamSocketListener.BindServiceNameAsync(String, SocketProtectionLevel) | bindServiceNameAsync(String, SocketProtectionLevel) method

Applies to Windows and Windows Phone

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

Syntax


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

public IAsyncAction BindServiceNameAsync(
  string localServiceName, 
  SocketProtectionLevel protectionLevel
)

Public Function BindServiceNameAsync(
  localServiceName As String,  
  protectionLevel As SocketProtectionLevel 
) As IAsyncAction

public:
IAsyncAction^ BindServiceNameAsync(
  String^ localServiceName, 
  SocketProtectionLevel protectionLevel
)

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.

Return value

Type: IAsyncAction

The asynchronous bind operation on a StreamSocketListener object.

Remarks

The BindServiceNameAsync(String, SocketProtectionLevel) method binds to the local IP addresses of all network interfaces on the local computer and to the local service name or TCP port specified in the localServiceName parameter. For Bluetooth RFCOMM, this method binds to the Bluetooth Service ID specified in the localServiceName parameter on all Bluetooth interfaces. 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. A Bluetooth Service ID must be supplied to bind for Bluetooth.

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

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

BindEndpointAsync
BindServiceNameAsync(String)
SocketProtectionLevel
StreamSocketListener
StreamSocketListenerInformation