StreamSocketControl 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供 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
- 繼承
- 屬性
Windows 需求
| 規格需求 | Description |
|---|---|
| 裝置系列 |
Windows 10 (已於 10.0.10240.0 引進)
|
| API contract |
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)
|
| 應用程式功能 |
bluetooth.rfcomm
|
備註
StreamSocketControl 類別提供存取 StreamSocket 物件上的進階套接字控制資料。
StreamSocketControl 物件會自動建立,使用父 StreamSocket 物件。 StreamSocket.Control 屬性提供對應 StreamSocketControl 物件的存取權限。
對於 StreamSocketControl 屬性值的任何變更,都必須在連接 StreamSocket 前設定。 因此,如果你需要對 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 | 最小保護等級 |
屬性
| 名稱 | Description |
|---|---|
| ClientCertificate |
取得或設定客戶端 SSL/TLS 憑證,當伺服器請求客戶端憑證時,該憑證會傳送給伺服器。 |
| IgnorableServerCertificateErrors |
取得一個 SSL 伺服器錯誤向量,讓它在使用 StreamSocket 進行 SSL 連線時可以忽略。 |
| KeepAlive |
一個表示 Keep-alive 封包是否會傳送到 StreamSocket 物件上的遠端目的地的值。 |
| MinProtectionLevel |
限制開發者使用 ConnectAsync() 或 UpgradeToSslAsync() 方法時所協商的 TLS 協定版本,這些方法需要 TLS。 |
| NoDelay |
一個表示 Nagle 演算法是否用於 StreamSocket 物件的值。 |
| OutboundBufferSizeInBytes |
傳送 StreamSocket 物件資料的 send buffer 大小(以位元組為單位)。 |
| OutboundUnicastHopLimit |
StreamSocket 物件傳送到單播 IP 位址的外發封包的跳躍限制。 |
| QualityOfService | |
| SerializeConnectionAttempts |
此值表示當多次連線嘗試時,嘗試是平行還是串行進行。 |