RGWebSocket 1.0.25
dotnet add package RGWebSocket --version 1.0.25
NuGet\Install-Package RGWebSocket -Version 1.0.25
<PackageReference Include="RGWebSocket" Version="1.0.25" />
<PackageVersion Include="RGWebSocket" Version="1.0.25" />
<PackageReference Include="RGWebSocket" />
paket add RGWebSocket --version 1.0.25
#r "nuget: RGWebSocket, 1.0.25"
#:package RGWebSocket@1.0.25
#addin nuget:?package=RGWebSocket&version=1.0.25
#tool nuget:?package=RGWebSocket&version=1.0.25
RGWebSocket - WebSocket Library for C# and Unity
RGWebsocketUnity is a powerful and user-friendly C# library that simplifies the process of building WebSocket clients in C#, and is suitable for direct integration into Unity. RGWebSocket is a similarly powerful and user-friendly C# library for building high-performance and multi-threaded WebSocket servers in C#. Both libraries reduce the complexities involved in handling WebSocket communications down to simple Connect/Disconnect/Send/Receive calls without you needing to worry about the details of handling WebSocket states.
Features
- Provides a basic HTTP server that allows you to register functions to handle specific URL paths.
- Automatically upgrades basic HTTP connections to WebSocket connections.
- Easy-to-use WebSocket client implementation for C# and Unity.
- Simplified WebSocket server creation in C# with multi-threading support.
- Abstracts away the complexities of WebSocket communication, allowing you to focus on your application logic.
- Compatible with standard WebSockets, since it is built on top of System.Net.WebSocket, including ws:// and wss:// protocols.
Installation
You can install RGWebSocket via NuGet Package Manager or by downloading the source code from GitHub.
NuGet Package Manager
To install RGWebSocket using NuGet, run the following command in the Package Manager Console:
Install-Package RGWebSocket
Manual Installation from GitHub
- Clone the RGWebSocket repository from GitHub.
- Include the necessary RGWebSocket files in your C# or Unity project.
Usage
WebSocket Client
RGWebSocket makes it incredibly easy to set up a WebSocket client in your C# or Unity project. Follow these simple steps:
using ReachableGames.RGWebSocket;
OnLogDelegate logger = (ELogVerboseType lvl, string msg) => { Console.WriteLine(msg) };
Action<UnityWebSocket> disconnectCallback = (UnityWebSocket uws) => { Console.WriteLine("Disconnected" };
int connectTimeoutMs = 3000;
// Create a new WebSocket client instance
UnityWebSocket client = UnityWebSocket(logger, "Client", disconnectCallback, connectTimeoutMs);
// Connect to the WebSocket server
Dictionary<string, string> headers = new Dictionary<string, string>();
await client.Connect("wss://your-websocket-server.com", headers).ConfigureAwait(false);
if (client.IsConnected)
{
// Send a message, does not block
client.Send("Mary had a little lamb.");
// Receive any waiting messages, does not block
List<UnityWebSocket.wsMessage> inboundMessages = new List<UnityWebSocket.wsMessage>();
client.ReceiveAll(inboundMessages);
// Kindly disconnect from the server
client.Close();
// Forcibly abort the connection, release memory, and prepare for new a Connect call
client.Shutdown();
}
WebSocket Server
Creating a multi-threaded WebSocket server with RGWebSocket is just as simple:
using ReachableGames.RGWebSocket;
OnLogDelegate logger = (ELogVerboseType lvl, string msg) => { Console.WriteLine(msg) };
int listenerTasks = 20;
int connectionTimeoutMs = 3000;
int idleSeconds = 60;
// Make the connection manager, which is told when a new websocket is connected and is also
// responsible for closing them if the server shuts down
IConnectionManager connectionMgr = new YourConnectionManager();
// Create a new WebSocket server instance on port
WebServer webServer = new WebServer("http://+:24680/", listenerTasks, connectionTimeoutMS, idleSeconds, connectionMgr, logger);
// Start the WebSocket server and run it until you hit the X key
Task webTask = Task.Run(webServer.Start);
while (Console.ReadKey().KeyChar!='X') {}
// Stop the web server, which tells the IConnectionManager to shutdown all the connections
webServer.Shutdown();
await webTask.ConfigureAwait(false);
Documentation
I wish there was more documentation for this library, but I haven't had time to write any yet. It's still in development, although I suspect the rate of change is slowing. The best guide for now is code in WebServer.cs and UnityWebSocket.cs and IConnectionManager.cs or ask questions.
Contributing
Although we welcome contributions to RGWebSocket, this is being used in several live products so bug fixes are all that can be considered for inclusion at present. If you have any suggestions for improvements, feel free to reach out.
License
RGWebSocket is released under the MIT License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net7.0
- Nito.AsyncEx.Coordination (>= 5.1.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.0.25 | 277 | 7/30/2023 |
1.0.24 | 248 | 7/27/2023 |
1.0.23 | 229 | 7/27/2023 |
1.0.22 | 245 | 6/25/2023 |
1.0.21 | 243 | 6/25/2023 |
1.0.20 | 241 | 6/25/2023 |
1.0.19 | 262 | 6/16/2023 |
1.0.18 | 388 | 1/30/2023 |
1.0.17 | 420 | 1/30/2023 |
1.0.16 | 407 | 1/29/2023 |
1.0.15 | 601 | 1/29/2022 |
1.0.14 | 439 | 12/7/2021 |
1.0.13 | 504 | 12/7/2021 |
1.0.12 | 769 | 10/14/2021 |
1.0.11 | 506 | 10/11/2021 |
1.0.10 | 683 | 10/3/2020 |
1.0.9 | 575 | 9/12/2020 |
1.0.8 | 590 | 9/11/2020 |
1.0.7 | 596 | 8/25/2020 |
1.0.6 | 546 | 8/25/2020 |
1.0.5 | 573 | 8/25/2020 |
1.0.4 | 594 | 8/25/2020 |
1.0.3 | 568 | 8/25/2020 |
1.0.2 | 550 | 8/24/2020 |
1.0.1 | 569 | 8/24/2020 |
1.0.0 | 587 | 8/24/2020 |