語言

StreamWebSocketControl 類別

定義

提供 StreamWebSocket 物件上的套接字控制資料。

public ref class StreamWebSocketControl sealed
public ref class StreamWebSocketControl sealed : IWebSocketControl2
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class StreamWebSocketControl final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class StreamWebSocketControl final : IWebSocketControl2
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class StreamWebSocketControl
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class StreamWebSocketControl : IWebSocketControl2
Public NotInheritable Class StreamWebSocketControl
Public NotInheritable Class StreamWebSocketControl
Implements IWebSocketControl2
繼承
Object Platform::Object IInspectable StreamWebSocketControl
屬性
實作

Windows 需求

規格需求 Description
裝置系列
Windows 10 (已於 10.0.10240.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)
應用程式功能
internetClient privateNetworkClientServer

備註

StreamWebSocketControl 類別提供存取 StreamWebSocket 物件上的進階套接字控制資料。

StreamWebSocketControl 物件會自動以父 StreamWebSocket 物件建立。 StreamWebSocket.Control 屬性提供對應 StreamWebSocketControl 物件的存取權限。

任何對 StreamWebSocketControl 屬性值的變更都必須在連接 StreamWebSocket 前設定好。 因此,如果你需要對 NoDelay、OutboundBufferSizeInBytes、ProxyCredential、ServerCredential 或 SupportedProtocols 屬性做變更,這些變更必須先完成,才能成功呼叫 StreamWebSocket 上的 ConnectAsync 方法。

以下範例建立 StreamWebSocket,並示範如何將 StreamWebSocketControl.NoDelay 屬性設定為 false。 (其他性質也可能以類似方式設定。)完成後,應用程式就能連接 StreamWebSocket。

using Windows.Networking.Sockets;

StreamWebSocket clientWebSocket = new StreamWebSocket();

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

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

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

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

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

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

StreamWebSocket^ clientWebSocket = ref new StreamWebSocket();

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

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

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

欲了解更多使用 StreamWebSocketControl 的資訊,請參閱 「如何使用進階 WebSocket 控制項」。

版本歷程記錄

Windows版本 SDK 版本 附加價值
1607 14393 IgnorableServerCertificateErrors
1709 16299 實際未請求的PongInterval
1709 16299 用戶端憑證
1709 16299 渴望的非請求PongInterval

屬性

名稱 Description
ActualUnsolicitedPongInterval

允許應用程式取得實際未經請求的 WebSocket PONG 間隔。

ClientCertificate

當建立安全 WebSocket 連線時,會取得客戶端提供的憑證。

DesiredUnsolicitedPongInterval

允許應用程式取得並設定想要的非請求 WebSocket PONG 間隔。

IgnorableServerCertificateErrors

會收到一份可忽略的伺服器憑證錯誤清單。 取得此清單,並在安全 WebSocket(wss:// 協定)伺服器憑證驗證過程中,新增 ChainValidationResult 值,以涵蓋您希望忽略的伺服器憑證錯誤。

NoDelay

一個表示 Nagle 演算法是否被用於 StreamWebSocket 物件的值。

OutboundBufferSizeInBytes

用於傳送 StreamWebSocket 物件資料的 send buffer 大小(以位元組為單位)。

ProxyCredential

用來透過 HTTP 標頭認證,使用 StreamWebSocket 物件向代理伺服器進行認證的憑證。

ServerCredential

用於透過 HTTP 標頭認證,使用 StreamWebSocket 物件驗證 WebSocket 伺服器的憑證。

SupportedProtocols

會獲得一個集合,可用來新增一份支援子協定清單,並在連線握手時向伺服器公告。

適用於