System.Net.WebSockets.WebSocketProtocol
$ dotnet add package System.Net.WebSockets.WebSocketProtocolProvides the WebSocketProtocol class, which allows creating a WebSocket from a connected stream using WebSocketsProtocol.CreateFromConnectedStream.
NOTE: This package was designed as a temporary solution for internal use (building ASP.NET targeting .NET Standard 2.0), and is now considered obsolete. If targeting .NET Standard 2.1 or .NET 5+, use WebSocket.CreateFromStream instead.
WebSocket instance that operates on the specified transport stream. The WebSocket class allows applications to send and receive data after the WebSocket upgrade has completed.WebSocket instances.To create a WebSocket using WebSocketProtocol, as a prerequisite, you need to prepare the opaque transport stream for the WebSocket, for example, create or accept a TCP socket connection as a Stream and perform a WebSocket opening handshake (upgrade) over it. Then you can use the transport stream and the negotiated subprotocol to call WebSocketProtocol.CreateFromStream.
Stream opaqueTransport = /* ... */; // complete WebSocket opening handshake over the transport connection
WebSocket ws = WebSocketProtocol.CreateFromStream(opaqueTransport, isServer: true, subProtocol, keepAliveInterval);
The API is considered obsolete and is not recommented for use.
On .NET Framework or .NET Standard 2.0:
WebSocket from a stream, use WebSocket.CreateClientWebSocket.
ClientWebSocket class.WebSocket from a stream is not available on the API surface, consider using HttpListener or ASP.NET HttpContext to accept server WebSocket connections.
On .NET Core 2.1+, .NET 5+ or .NET Standard 2.1:
WebSocket from a stream, use WebSocket.CreateFromStreamThe main types provided by this library are:
System.Net.WebSockets.WebSocketProtocol is released as open source under the MIT license.