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
派生
实现

注解

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 只支持客户端和服务器 Websocket 的公共实现。However, the only public implementations of client and server WebSockets are supported on Windows 8 and Windows Server 2012. System.Net.WebSockets windows 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 类的实例。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>)

此 API 支持产品基础结构,不能在代码中直接使用。

允许调用方创建客户端 WebSocket 类,此类为组帧目的将使用 WSPC。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 和自承载实现的非托管资源。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 为目标。Returns a value that indicates if the WebSocket instance is targeting .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 的浅表副本。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)

WebSocket 连接异步接收数据。Receives data from the WebSocket connection asynchronously.

RegisterPrefixes()

此 API 支持产品基础结构,不能在代码中直接使用。

允许调用方注册 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)

通过 WebSocket 连接异步发送数据。Sends data over the WebSocket connection asynchronously.

ThrowOnInvalidState(WebSocketState, WebSocketState[])

验证连接是否处于预期状态。Verifies that the connection is in an expected state.

ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

适用于