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
WebSocketinstance that operates on the specified transport stream. TheWebSocketclass allows applications to send and receive data after theWebSocketupgrade has completed. - The API can be used to create both client-side and server-side
WebSocketinstances.
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
WebSocketfrom a stream, useWebSocket.CreateClientWebSocket.- Alternatively, consider using a
ClientWebSocketclass.
- Alternatively, consider using a
- Creating a server
WebSocketfrom a stream is not available on the API surface, consider usingHttpListeneror ASP.NETHttpContextto accept server WebSocket connections.
On .NET Core 2.1+, .NET 5+ or .NET Standard 2.1:
- To create a client or server
WebSocketfrom 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.
|
22 |
|
Microsoft.AspNetCore.WebSockets
ASP.NET Core web socket middleware for use on top of opaque servers.
|
21 |
|
Microsoft.AspNetCore.All
Provides a default set of APIs for building an ASP.NET Core application, and also includes API for third-party integrations with ASP.NET Core.
This package requires the ASP.NET Core runtime. This runtime is installed by the .NET Core SDK, or can be acquired separately using installers available at https://aka.ms/dotnet-download.
|
21 |
|
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
|
20 |
|
Microsoft.AspNetCore.Http.Connections
Components for providing real-time bi-directional communication across the Web.
|
20 |
|
Microsoft.AspNetCore.All
Provides a default set of APIs for building an ASP.NET Core application, and also includes API for third-party integrations with ASP.NET Core.
This package requires the ASP.NET Core runtime. This runtime is installed by the .NET Core SDK, or can be acquired separately using installers available at https://aka.ms/dotnet-download.
|
20 |
|
Microsoft.AspNetCore.WebSockets
ASP.NET Core web socket middleware for use on top of opaque servers.
|
19 |
|
Microsoft.AspNetCore.Http.Connections
Components for providing real-time bi-directional communication across the Web.
|
19 |
|
Microsoft.AspNetCore.All
Provides a default set of APIs for building an ASP.NET Core application, and also includes API for third-party integrations with ASP.NET Core.
This package requires the ASP.NET Core runtime. This runtime is installed by the .NET Core SDK, or can be acquired separately using installers available at https://aka.ms/dotnet-download.
|
18 |
|
Microsoft.AspNetCore.WebSockets
ASP.NET Core web socket middleware for use on top of opaque servers.
|
18 |
|
Microsoft.AspNetCore.WebSockets
ASP.NET Core web socket middleware for use on top of opaque servers.
|
17 |
|
Microsoft.AspNetCore.All
Provides a default set of APIs for building an ASP.NET Core application, and also includes API for third-party integrations with ASP.NET Core.
This package requires the ASP.NET Core runtime. This runtime is installed by the .NET Core SDK, or can be acquired separately using installers available at https://aka.ms/dotnet-download.
|
17 |
|
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
|
16 |
|
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
|
16 |
|
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
|
16 |
|
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
|
16 |
.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)