WebSocket WebSocket WebSocket WebSocket Class

定義

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
繼承
WebSocketWebSocketWebSocketWebSocket
衍生
實作

備註

中的某些類別System.Net.WebSocketsWindows 7、 Windows Vista SP2 和 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 上支援的用戶端和伺服器 WebSockets 只有 public 的實作。However, the only public implementations of client and server WebSockets are supported on Windows 8 and Windows Server 2012. 類別和類別中的項目System.Net.WebSocketsWindows 7、 Windows Vista SP2 和 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() WebSocket() WebSocket()

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

屬性

CloseStatus CloseStatus CloseStatus CloseStatus

表示遠端端點已起始關閉訊號交換的原因。Indicates the reason why the remote endpoint initiated the close handshake.

CloseStatusDescription CloseStatusDescription CloseStatusDescription CloseStatusDescription

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

DefaultKeepAliveInterval DefaultKeepAliveInterval DefaultKeepAliveInterval DefaultKeepAliveInterval

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

State State State State

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

SubProtocol SubProtocol SubProtocol SubProtocol

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

方法

Abort() Abort() Abort() Abort()

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

CloseAsync(WebSocketCloseStatus, String, CancellationToken) CloseAsync(WebSocketCloseStatus, String, CancellationToken) CloseAsync(WebSocketCloseStatus, String, CancellationToken) 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) CloseOutputAsync(WebSocketCloseStatus, String, CancellationToken) CloseOutputAsync(WebSocketCloseStatus, String, CancellationToken) CloseOutputAsync(WebSocketCloseStatus, String, CancellationToken)

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

CreateClientBuffer(Int32, Int32) CreateClientBuffer(Int32, Int32) CreateClientBuffer(Int32, Int32) CreateClientBuffer(Int32, Int32)

建立用戶端若要以此方式使用的緩衝區WebSocket執行個體。Create client buffers to use with this WebSocket instance.

CreateClientWebSocket(Stream, String, Int32, Int32, TimeSpan, Boolean, ArraySegment<Byte>) CreateClientWebSocket(Stream, String, Int32, Int32, TimeSpan, Boolean, ArraySegment<Byte>) CreateClientWebSocket(Stream, String, Int32, Int32, TimeSpan, Boolean, ArraySegment<Byte>) 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) CreateFromStream(Stream, Boolean, String, TimeSpan) CreateFromStream(Stream, Boolean, String, TimeSpan) 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) CreateServerBuffer(Int32) CreateServerBuffer(Int32) CreateServerBuffer(Int32)

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

Dispose() Dispose() Dispose() Dispose()

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

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

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

(Inherited from Object)
GetType() GetType() GetType() GetType()

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

(Inherited from Object)
IsApplicationTargeting45() IsApplicationTargeting45() IsApplicationTargeting45() IsApplicationTargeting45()

傳回值,這個值,指出 WebSocket 執行個體以目標.NET Framework 4.5.NET Framework 4.5Returns a value that indicates if the WebSocket instance is targeting .NET Framework 4.5.NET Framework 4.5.

IsStateTerminal(WebSocketState) IsStateTerminal(WebSocketState) IsStateTerminal(WebSocketState) IsStateTerminal(WebSocketState)

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

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

(Inherited from Object)
ReceiveAsync(ArraySegment<Byte>, CancellationToken) ReceiveAsync(ArraySegment<Byte>, CancellationToken) ReceiveAsync(ArraySegment<Byte>, CancellationToken) ReceiveAsync(ArraySegment<Byte>, CancellationToken)

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

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

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

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

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

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

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

ToString() ToString() ToString() ToString()

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

(Inherited from Object)

適用於