Share via


StreamSocketListener.BindServiceNameAsync 方法

定义

重载

BindServiceNameAsync(String)

StreamSocketListener 启动对本地服务名称的绑定操作。

BindServiceNameAsync(String, SocketProtectionLevel)

StreamSocketListener 上启动对本地服务名称的绑定操作,该名称具有要在任何绑定套接字上设置的指定 SocketProtectionLevel

BindServiceNameAsync(String, SocketProtectionLevel, NetworkAdapter)

StreamSocketListener 上启动对指定网络适配器上的本地服务名称的套接字绑定操作,并在任何绑定套接字上设置指定的 SocketProtectionLevel

BindServiceNameAsync(String)

StreamSocketListener 启动对本地服务名称的绑定操作。

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

参数

localServiceName
String

Platform::String

winrt::hstring

要绑定 StreamSocketListener 对象的本地服务名称或 TCP 端口。 对于蓝牙 RFCOMM,此参数是蓝牙服务 ID。

返回

对 StreamSocketListener 对象执行的异步绑定操作。

属性

注解

BindServiceNameAsync (String) 方法绑定到本地计算机上所有网络接口的本地 IP 地址,以及 localServiceName 参数中指定的本地服务名称或 TCP 端口。 如果 localServiceName 参数为空字符串,则系统将选择要绑定的本地 TCP 端口。

对于蓝牙 RFCOMM,此方法绑定到所有蓝牙接口上的 localServiceName 参数中指定的蓝牙服务 ID。 必须提供蓝牙服务 ID 才能绑定蓝牙。

如果另一个应用 (另一个 StreamSocketListener,则 BindServiceNameAsync (String) 方法将失败,例如,) 已绑定到 localServiceName 参数中指定的本地 TCP 端口或蓝牙服务 ID。

另请参阅

适用于

BindServiceNameAsync(String, SocketProtectionLevel)

StreamSocketListener 上启动对本地服务名称的绑定操作,该名称具有要在任何绑定套接字上设置的指定 SocketProtectionLevel

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

参数

localServiceName
String

Platform::String

winrt::hstring

要绑定 StreamSocketListener 对象的本地服务名称或 TCP 端口。 对于蓝牙 RFCOMM,此参数是蓝牙服务 ID。

protectionLevel
SocketProtectionLevel

在任何绑定套接字上设置的加密保护级别。

返回

对 StreamSocketListener 对象执行的异步绑定操作。

属性

注解

[BindServiceNameAsync (String, SocketProtectionLevel) 方法绑定到本地计算机上所有网络接口的本地 IP 地址,以及 localServiceName 参数中指定的本地服务名称或 TCP 端口。 对于蓝牙 RFCOMM,此方法绑定到所有蓝牙接口上的 localServiceName 参数中指定的蓝牙服务 ID。 此方法将任何绑定套接字上的加密保护级别设置为 protectionLevel 参数。

如果 localServiceName 参数为空字符串,则系统将选择要绑定的本地 TCP 端口。 必须提供蓝牙服务 ID 才能绑定蓝牙。

如果另一个应用 (另一个 StreamSocketListener,则 [BindServiceNameAsync (String, SocketProtectionLevel) 方法将失败,例如,) 已绑定到 localServiceName 参数中指定的本地 TCP 端口或蓝牙服务 ID。

对于所有套接字, protectionLevel 参数必须设置为 PlainSocket ,但蓝牙上使用的套接字除外。 当要通过蓝牙使用套接字时, protectionLevel 参数可以设置为 PlainSocketBluetoothEncryptionAllowNullAuthenticationBluetoothEncryptionWithAuthentication。 有关详细信息,请参阅 SocketProtectionLevel 枚举。

另请参阅

适用于

BindServiceNameAsync(String, SocketProtectionLevel, NetworkAdapter)

StreamSocketListener 上启动对指定网络适配器上的本地服务名称的套接字绑定操作,并在任何绑定套接字上设置指定的 SocketProtectionLevel

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

参数

localServiceName
String

Platform::String

winrt::hstring

要绑定 StreamSocketListener 对象的本地服务名称或 TCP 端口。 对于蓝牙 RFCOMM,此参数是蓝牙服务 ID。

protectionLevel
SocketProtectionLevel

在任何绑定套接字上设置的加密保护级别。

adapter
NetworkAdapter

要绑定 StreamSocketListener 对象的网络适配器。

返回

对 StreamSocketListener 对象执行的异步绑定操作。

属性

注解

[BindServiceNameAsync (String、SocketProtectionLevel、NetworkAdapter) 方法绑定到本地计算机上的网络适配器上 localServiceName 参数中指定的本地服务名称或 TCP 端口。 对于蓝牙 RFCOMM,如果适配器参数为 null,此方法将绑定到 localServiceName 参数中指定的蓝牙服务 ID。 必须提供蓝牙服务 ID 才能绑定蓝牙。 如果在 适配器参数中 指定了网络适配器,并且 localServiceName 参数包含蓝牙服务 ID,则此方法将失败。

此方法将任何绑定套接字上的加密保护级别设置为 protectionLevel 参数。

如果 localServiceName 参数为空字符串,则系统将选择要绑定的本地 TCP 端口。 如果 TCP 套接字绑定的 适配器 参数为 null ,则会发生错误。

[BindServiceNameAsync (String、SocketProtectionLevel、NetworkAdapter) 方法使用的名称解析机制仅限于域名系统 (DNS) 命名空间的指定接口。

如果另一个应用 (另一个 StreamSocketListener,则 [BindServiceNameAsync (String、SocketProtectionLevel、NetworkAdapter) 方法将失败,例如,) 已绑定到适配器参数中指定的网络适配器上的 localServiceName 参数中指定的本地 TCP 端口。 对于蓝牙,如果另一个应用 (另一个 StreamSocketListener(例如,) 已绑定到 localServiceName 参数中指定的蓝牙服务 ID),此方法将失败。

使用指定的网络适配器是尽最大努力的。 在弱主机或转发模式下配置了适配器的系统可能使用指定适配器以外的适配器。

对于所有套接字, protectionLevel 参数必须设置为 PlainSocket ,但蓝牙上使用的套接字除外。 当要通过蓝牙使用套接字时, protectionLevel 参数可以设置为 PlainSocketBluetoothEncryptionAllowNullAuthenticationBluetoothEncryptionWithAuthentication。 有关详细信息,请参阅 SocketProtectionLevel 枚举。

另请参阅

适用于