McComms.Sockets
1.0.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package McComms.Sockets --version 1.0.1
NuGet\Install-Package McComms.Sockets -Version 1.0.1
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.Sockets" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="McComms.Sockets" Version="1.0.1" />
<PackageReference Include="McComms.Sockets" />
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.Sockets --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: McComms.Sockets, 1.0.1"
#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.Sockets@1.0.1
#: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.Sockets&version=1.0.1
#tool nuget:?package=McComms.Sockets&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
McComms.Sockets
Socket-based implementation for the McComms solution. This package provides TCP/IP socket-based implementations of the ICommsClient and ICommsServer interfaces from McComms.Core.
TCP/IP Socket Communication Model
This implementation uses plain TCP/IP sockets with a simple text-based protocol for communication.
Message Format
All messages are sent as UTF-8 encoded strings with the following format:
Command Request:
CMD:ID:MESSAGE
Command Response:
RES:SUCCESS:ID:MESSAGE
Broadcast Message:
BRD:ID:MESSAGE
Connection Flow
+--------+ +--------+
| Client | | Server |
+--------+ +--------+
| |
| TCP Connection Request |
|---------------------------------->|
| |
| TCP Connection Established |
|<----------------------------------|
| |
Command Flow
+--------+ +--------+
| Client | | Server |
+--------+ +--------+
| |
| CMD:1:Hello Server |
|---------------------------------->|
| | Process
| | Command
| |
| RES:true:1:Command processed |
|<----------------------------------|
| |
Broadcast Flow
+--------+ +--------+
| Server | | Client |
+--------+ +--------+
| |
| BRD:1:System notification |
|---------------------------------->|
| |
| +--------+
| | Client |
| +--------+
| BRD:1:System notification |
|---------------------------------->|
| |
Example Usage
Server
// Create a Socket server on port 9000
var server = new CommsServerSockets(IPAddress.Parse("127.0.0.1"), 9000);
// 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 Socket client
var client = new CommsClientSockets(IPAddress.Parse("127.0.0.1"), 9000);
// 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();
}
Benefits of Socket-based Implementation
- Lightweight: Minimal overhead compared to higher-level protocols
- Reliable: Built on established TCP/IP technology
- Cross-Platform: Works on any platform that supports standard sockets
- Direct Control: Fine-grained control over connection handling
- Low Latency: Optimized for performance with minimal protocol overhead
Contents
- Socket clients and servers
- Specific models and helpers
Author
Joan Magnet
Product | Versions 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.
-
net9.0
- McComms.Core (>= 1.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.