System.Net.WebSockets.WebSocketProtocol 5.1.0
About
Provides 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.
Key Features
- Creates a new
WebSocket
instance that operates on the specified transport stream. TheWebSocket
class allows applications to send and receive data after theWebSocket
upgrade has completed. - The API can be used to create both client-side and server-side
WebSocket
instances.
How to Use
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);
Remarks
The API is considered obsolete and is not recommented for use.
On .NET Framework or .NET Standard 2.0:
- To create a client
WebSocket
from a stream, useWebSocket.CreateClientWebSocket
.- Alternatively, consider using a
ClientWebSocket
class.
- Alternatively, consider using a
- Creating a server
WebSocket
from a stream is not available on the API surface, consider usingHttpListener
or ASP.NETHttpContext
to accept server WebSocket connections.
On .NET Core 2.1+, .NET 5+ or .NET Standard 2.1:
- To create a client or server
WebSocket
from a stream, useWebSocket.CreateFromStream
Main Types
The main types provided by this library are:
- System.Net.WebSockets.WebSocketProtocol
Additional Documentation
- API reference can be found in: https://learn.microsoft.com/en-us/dotnet/api/system.net.websockets.websocketprotocol
- Additional APIs mentioned:
- WebSocket static methods: https://learn.microsoft.com/en-us/dotnet/api/system.net.websockets.websocket
- ClientWebSocket: https://learn.microsoft.com/en-us/dotnet/api/system.net.websockets.clientwebsocket
- HttpListener context: https://learn.microsoft.com/en-us/dotnet/api/system.net.httplistenercontext
- ASP.NET HttpContext: https://learn.microsoft.com/en-us/dotnet/api/system.web.httpcontext
License
System.Net.WebSockets.WebSocketProtocol is released as open source under the MIT license.
Showing the top 20 packages that depend on System.Net.WebSockets.WebSocketProtocol.
Packages | Downloads |
---|---|
Microsoft.AspNetCore.WebSockets
ASP.NET Core web socket middleware for use on top of opaque servers.
|
59 |
Microsoft.AspNetCore.WebSockets
ASP.NET Core web socket middleware for use on top of opaque servers.
|
54 |
Microsoft.AspNetCore.WebSockets
ASP.NET Core web socket middleware for use on top of opaque servers.
This package was built from the source code at https://github.com/aspnet/AspNetCore/tree/0f9ad16b096ca2535d77efd2ad27645449421b44
|
53 |
Microsoft.AspNetCore.WebSockets
ASP.NET Core web socket middleware for use on top of opaque servers.
This package was built from the source at:
https://github.com/aspnet/WebSockets/tree/56f90124026b1da5f260b3c1a55f75fab7ecbb68
|
48 |
Microsoft.AspNetCore.WebSockets
ASP.NET Core web socket middleware for use on top of opaque servers.
|
47 |
Microsoft.AspNetCore.WebSockets
ASP.NET Core web socket middleware for use on top of opaque servers.
This package was built from the source at:
https://github.com/aspnet/WebSockets/tree/6d565e3a8a6ab74d27ce2e1bbc64e58ad242cd99
|
45 |
Microsoft.AspNetCore.WebSockets
ASP.NET Core web socket middleware for use on top of opaque servers.
This package was built from the source code at https://github.com/aspnet/AspNetCore/tree/ce8cf65589734f82b0536c543aba5bd60d0a5a98
|
44 |
Microsoft.AspNetCore.WebSockets
ASP.NET Core web socket middleware for use on top of opaque servers.
|
44 |
Microsoft.AspNetCore.WebSockets
ASP.NET Core web socket middleware for use on top of opaque servers.
This package was built from the source at:
https://github.com/aspnet/WebSockets/tree/ecadd7b7b1378f8722b868335cca0161e935d2ff
|
41 |
Microsoft.AspNetCore.WebSockets
ASP.NET Core web socket middleware for use on top of opaque servers.
|
41 |
.NET Framework 4.6.2
- System.Buffers (>= 4.6.0)
- System.Memory (>= 4.6.0)
- System.Numerics.Vectors (>= 4.6.0)
- System.Runtime.CompilerServices.Unsafe (>= 6.1.0)
- System.Threading.Tasks.Extensions (>= 4.6.0)
.NET 6.0
- No dependencies.
.NET Standard 2.0
- System.Buffers (>= 4.6.0)
- System.Memory (>= 4.6.0)
- System.Numerics.Vectors (>= 4.6.0)
- System.Runtime.CompilerServices.Unsafe (>= 6.1.0)
- System.Threading.Tasks.Extensions (>= 4.6.0)