语言

StreamSocketControl 类

定义

在 StreamSocket 对象上提供套接字控制数据。

public ref class StreamSocketControl sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class StreamSocketControl final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class StreamSocketControl
Public NotInheritable Class StreamSocketControl
继承
Object Platform::Object IInspectable StreamSocketControl
属性

Windows 要求

要求 说明
设备系列
Windows 10 (在 10.0.10240.0 中引入)
API contract
Windows.Foundation.UniversalApiContract (在 v1.0 中引入)
应用功能
bluetooth.rfcomm

注解

StreamSocketControl 类提供对 StreamSocket 对象上高级套接字控制数据的访问。

使用父 StreamSocket 对象自动创建 StreamSocketControl 对象。 StreamSocket.Control 属性提供对关联的 StreamSocketControl 对象的访问。

在 StreamSocket 连接之前,必须设置对 StreamSocketControl 上的属性值所做的任何更改。 因此,如果需要更改 ClientCertificate、IgnorableServerCertificateErrors、KeepAlive、NoDelay、OutboundBufferSizeInBytes、OutboundUnicastHopLimit 或 QualityOfService 属性,则必须在成功调用 StreamSocket 上的某个 ConnectAsync 方法之前进行这些更改。

使用 ClientCertificate 设置用于通过关联的 StreamSocket 对象建立安全连接的客户端证书。

以下示例创建 StreamSocket,然后演示如何将 NoDelay 属性设置为 false。 其他属性可以采用类似的方式进行设置。 完成此操作后,应用可以连接 StreamSocket。

using Windows.Networking.Sockets;

StreamSocket clientSocket = new StreamSocket();

// Get the current setting for this option.
// This isn't required, but it shows how to get the current setting.
bool currentSetting = clientSocket.Control.NoDelay;

// Set NoDelay to false so that the Nagle algorithm is not disabled.
clientSocket.Control.NoDelay = false;

// Now you can call the ConnectAsync method to connect the StreamSocket.
#include <winrt/Windows.Networking.Sockets.h>
using namespace winrt;
...
Windows::Networking::Sockets::StreamSocket clientSocket;

// Get the current setting for this option.
// This isn't required, but it shows how to get the current setting.
bool currentSetting{ clientSocket.Control().NoDelay() };

// Set NoDelay to false so that the Nagle algorithm is not disabled.
clientSocket.Control().NoDelay(false);

// Now you can call the ConnectAsync function to connect the StreamSocket.
using namespace Windows::Networking::Sockets;

StreamSocket^ clientSocket = ref new StreamSocket();

// Get the current setting for this option.
// This isn't required, but it shows how to get the current setting.
bool currentSetting = clientSocket->Control->NoDelay;

// Set NoDelay to false so that the Nagle algorithm is not disabled.
clientSocket->Control->NoDelay = false;

// Now you can call the ConnectAsync method to connect the StreamSocket.

有关使用 StreamSocketControl 的详细信息,请参阅 如何使用高级套接字控件。

版本历史记录

Windows 版本 SDK 版本 附加值
1709 16299 MinProtectionLevel

属性

名称 说明
ClientCertificate

获取或设置客户端 SSL/TLS 证书,如果服务器请求客户端证书,该证书将发送到服务器。

IgnorableServerCertificateErrors

获取与 StreamSocket 建立 SSL 连接时要忽略的 SSL 服务器错误的向量。

KeepAlive

一个值,该值指示是否将保持活动数据包发送到 StreamSocket 对象的远程目标。

MinProtectionLevel

约束当开发人员使用需要 TLS 的 ConnectAsync() 或 UpgradeToSslAsync() 方法时将协商的 TLS 协议版本。

NoDelay

一个值,该值指示是否在 StreamSocket 对象上使用 Nagle 算法。

OutboundBufferSizeInBytes

要用于在 StreamSocket 对象上发送数据的发送缓冲区的大小(以字节为单位)。

OutboundUnicastHopLimit

StreamSocket 对象发送到单播 IP 地址的出站数据包的跃点限制。

QualityOfService

StreamSocket 对象的服务质量。

SerializeConnectionAttempts

一个值,该值指示在进行多个连接尝试时,尝试是并行还是串行进行。

适用于

另请参阅