WebSocket 類別

定義

WebSocket 類別允許應用程式在 WebSocket 升級完成後傳送和接收資料。The WebSocket class allows applications to send and receive data after the WebSocket upgrade has completed.

public ref class WebSocket abstract : IDisposable
public abstract class WebSocket : IDisposable
type WebSocket = class
    interface IDisposable
Public MustInherit Class WebSocket
Implements IDisposable
繼承
WebSocket
衍生
實作

備註

Windows 7、windows Vista SP2 System.Net.WebSockets和 windows Server 2008 支援命名空間中的某些類別。Some of the classes in the System.Net.WebSockets namespace are supported on Windows 7, Windows Vista SP2, and Windows Server 2008. 不過,Windows 8 和 Windows Server 2012 僅支援用戶端和伺服器 Websocket 的唯一公用部署。However, the only public implementations of client and server WebSockets are supported on Windows 8 and Windows Server 2012. 在 windows 7、windows Vista SP2 System.Net.WebSockets和 windows Server 2008 上支援的命名空間中的類別和類別元素是抽象類別。The classes and class elements in the System.Net.WebSockets namespace that are supported on Windows 7, Windows Vista SP2, and Windows Server 2008 are abstract classes. 這可讓應用程式開發人員以實際的用戶端 Websocket 執行來繼承和擴充這些抽象類別。This allows an application developer to inherit and extend these abstract classes with an actual implementation of client WebSockets.

建構函式

WebSocket()

建立 WebSocket 類別的執行個體。Creates an instance of the WebSocket class.

屬性

CloseStatus

指出遠端端點為什麼啟始關閉信號交換的原因。Indicates the reason why the remote endpoint initiated the close handshake.

CloseStatusDescription

允許遠端端點描述連線關閉的原因。Allows the remote endpoint to describe the reason why the connection was closed.

DefaultKeepAliveInterval

取得預設 WebSocket 通訊協定保持連接間隔。Gets the default WebSocket protocol keep-alive interval.

State

傳回 WebSocket 連接的目前狀態。Returns the current state of the WebSocket connection.

SubProtocol

取得開始信號交握期間所交涉的子通訊協定。Gets the subprotocol that was negotiated during the opening handshake.

方法

Abort()

中止 WebSocket 連線並取消任何暫止 IO 作業。Aborts the WebSocket connection and cancels any pending IO operations.

CloseAsync(WebSocketCloseStatus, String, CancellationToken)

以非同步作業使用 WebSocket 通訊協定規格第 7 節中所定義的關閉信號交換,關閉 WebSocket 連接。Closes the WebSocket connection as an asynchronous operation using the close handshake defined in the WebSocket protocol specification section 7.

CloseOutputAsync(WebSocketCloseStatus, String, CancellationToken)

啟始或完成 WebSocket 通訊協定規格第 7 節中定義的關閉信號交換。Initiates or completes the close handshake defined in the WebSocket protocol specification section 7.

CreateClientBuffer(Int32, Int32)

建立要與這個 WebSocket 執行個體搭配使用的用戶端緩衝區。Create client buffers to use with this WebSocket instance.

CreateClientWebSocket(Stream, String, Int32, Int32, TimeSpan, Boolean, ArraySegment<Byte>)

允許呼叫端建立使用 WSPC 進行框架處理的用戶端 WebSocket 類別。Allows callers to create a client side WebSocket class which will use the WSPC for framing purposes.

CreateFromStream(Stream, Boolean, String, TimeSpan)

建立新的 WebSocket 物件,其會在指定的資料流上運作,表示 Web 通訊端連線。Creates a new WebSocket object that operates on the specified stream, which represents a web socket connection.

CreateServerBuffer(Int32)

建立 WebSocket 伺服器緩衝區。Creates a WebSocket server buffer.

Dispose()

用來清除 ASP.NET 的 Unmanaged 資源和自我裝載的實作。Used to clean up unmanaged resources for ASP.NET and self-hosted implementations.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
IsApplicationTargeting45()

傳回表示 WebSocket 執行個體是否以 .NET Framework 4.5.NET Framework 4.5 為目標的值。Returns a value that indicates if the WebSocket instance is targeting .NET Framework 4.5.NET Framework 4.5.

IsStateTerminal(WebSocketState)

傳回值,指出 WebSocket 執行個體的狀態是關閉或中止。Returns a value that indicates if the state of the WebSocket instance is closed or aborted.

MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
ReceiveAsync(ArraySegment<Byte>, CancellationToken)

以非同步方式從 WebSocket 連接接收資料。Receives data from the WebSocket connection asynchronously.

ReceiveAsync(Memory<Byte>, CancellationToken)
RegisterPrefixes()

允許呼叫端註冊 WebSocket 要求 (ws 和 wss) 的前置詞。Allows callers to register prefixes for WebSocket requests (ws and wss).

SendAsync(ArraySegment<Byte>, WebSocketMessageType, Boolean, CancellationToken)

以非同步的方式透過 WebSocket 連線傳送資料。Sends data over the WebSocket connection asynchronously.

SendAsync(ReadOnlyMemory<Byte>, WebSocketMessageType, Boolean, CancellationToken)
ThrowOnInvalidState(WebSocketState, WebSocketState[])

確認連接處於預期的狀態。Verifies that the connection is in an expected state.

ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

適用於