McComms.WebSockets 1.0.4

dotnet add package McComms.WebSockets --version 1.0.4
                    
NuGet\Install-Package McComms.WebSockets -Version 1.0.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="McComms.WebSockets" Version="1.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="McComms.WebSockets" Version="1.0.4" />
                    
Directory.Packages.props
<PackageReference Include="McComms.WebSockets" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add McComms.WebSockets --version 1.0.4
                    
#r "nuget: McComms.WebSockets, 1.0.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package McComms.WebSockets@1.0.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=McComms.WebSockets&version=1.0.4
                    
Install as a Cake Addin
#tool nuget:?package=McComms.WebSockets&version=1.0.4
                    
Install as a Cake Tool

McComms.WebSockets

WebSockets implementation for the McComms communication library.

This package provides WebSockets-based implementations of the ICommsClient and ICommsServer interfaces from McComms.Core, allowing for bidirectional communication over WebSockets.

Communication Flow with WebSockets

WebSockets provide a full-duplex communication channel over a single TCP connection, making them ideal for real-time applications.

Connection Establishment

+--------+                           +--------+
| Client |                           | Server |
+--------+                           +--------+
    |                                    |
    | WebSocket Connection Request       |
    |----------------------------------->|
    |                                    |
    | WebSocket Connection Established   |
    |<-----------------------------------|
    |                                    |

Command Request/Response

+--------+                           +--------+
| Client |                           | Server |
+--------+                           +--------+
    |                                    |
    | WS Message: CommandRequest JSON    |
    |----------------------------------->|
    |                                    | Process
    |                                    | Command
    |                                    |
    | WS Message: CommandResponse JSON   |
    |<-----------------------------------|
    |                                    |

Broadcast Message

+--------+                           +--------+
| Server |                           | Client |
+--------+                           +--------+
    |                                    |
    | WS Message: BroadcastMessage JSON  |
    |----------------------------------->|
    |                                    |
    |                            +--------+
    |                            | Client |
    |                            +--------+
    | WS Message: BroadcastMessage JSON  |
    |----------------------------------->|
    |                                    |

Example

Server

// Create a WebSockets server on port 8080
var server = new CommsServerWebSockets("localhost", 8080);

// Start the server with a command handler
server.Start((request) => {
    Console.WriteLine($"Received command: {request.Id} - {request.Message}");
    return new CommandResponse(true, request.Id.ToString(), "Command processed");
});

// Send a broadcast message to all connected clients
server.SendBroadcast(new BroadcastMessage(1, "System notification"));

// Later, when application ends
server.Stop();

Client

// Create a WebSockets client
var client = new CommsClientWebSockets("localhost", 8080);

// Connect and set up broadcast message handler
var connected = await client.ConnectAsync((broadcast) => {
    Console.WriteLine($"Received broadcast: {broadcast.Id} - {broadcast.Message}");
});

if (connected)
{
    // Send a command
    var request = new CommandRequest(1, "Hello Server");
    var response = await client.SendCommandAsync(request);
    
    Console.WriteLine($"Response: {response.Success} - {response.Message}");
    
    // When done
    await client.DisconnectAsync();
}

Features

  • WebSockets client implementation
  • WebSockets server implementation
  • Compatible with all McComms core interfaces
  • Real-time bidirectional communication
  • Asynchronous APIs for modern application development

Usage

Refer to the demo applications for more examples of how to use this library.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.4 156 5/28/2025
1.0.3 151 5/28/2025
1.0.1 152 5/26/2025
1.0.0 150 5/26/2025