SocketCommand.Abstractions
1.0.6
See the version list below for details.
dotnet add package SocketCommand.Abstractions --version 1.0.6
NuGet\Install-Package SocketCommand.Abstractions -Version 1.0.6
<PackageReference Include="SocketCommand.Abstractions" Version="1.0.6" />
<PackageVersion Include="SocketCommand.Abstractions" Version="1.0.6" />
<PackageReference Include="SocketCommand.Abstractions" />
paket add SocketCommand.Abstractions --version 1.0.6
#r "nuget: SocketCommand.Abstractions, 1.0.6"
#:package SocketCommand.Abstractions@1.0.6
#addin nuget:?package=SocketCommand.Abstractions&version=1.0.6
#tool nuget:?package=SocketCommand.Abstractions&version=1.0.6
β‘ SocketCommand
SocketCommand is a modern, extensible NuGet package that makes socket-based command communication simple and powerful in .NET applications.
Built on top of .NET hosting, it supports:
- π Command-based duplex communication
- π§± Entity serialization
- π AES encryption
- π¦ Compression
- π‘ UDP-based peer discovery
- π Dependency Injection-friendly design
π¦ Installation
SocketCommand consists of two packages:
Package | Purpose |
---|---|
SocketCommand.Abstractions |
π― Lightweight project with interfaces and attributes. Add this wherever you define socket-bound entities. |
SocketCommand.Hosting |
π Core socket server/client logic. Add this to your startup project. |
SocketCommand.Compression.7Zip |
ποΈCompress messages using 7Zip/LZMA. Add this to your startup project. |
Install via NuGet:
dotnet add package SocketCommand.Hosting
dotnet add package SocketCommand.Abstractions
dotnet add package SocketCommand.Compression.7Zip
βοΈ Configuration
Define your settings in appsettings.json
:
{
"SocketCommand": {
"Port": 5000,
"BufferSize": 1024,
"UdpPort": 5052,
"UdpSecret": "s3cr3t!",
"AESKey": "jiwlQEjVDC67rIbte8n0XoZZzgXE4cSnRlj81YZaAf4=",
"AESIV": "ivgVH9nmCwAafSK2jhyA1Q=="
}
}
Property | Description |
---|---|
Port |
TCP server port. Use 0 for a random port. |
BufferSize |
Size of the read buffer. Default: 1024 . |
UdpPort |
Port for UDP discovery. |
UdpSecret |
Shared secret to verify discovery packets. Must match on both ends. |
AESKey / AESIV |
π AES encryption key and IV. Both must match across peers. |
π Decorating Entities
Entities that are to be used as commands or responses must be decorated with the SocketCommandAttribute
and OrderAttribute
. The order attribute must batch on entities on both ends.
[SocketMessage]
public class TestEntity
{
[Order(1)]
public int Id { get; set; }
[Order(2)]
public string Name { get; set; }
}
π Usage
Host Initialization
var builder = Host.CreateApplicationBuilder(args);
builder.AddSocketCommand()
.With7ZipCompression()
.WithAESEncryption()
.WithCommand("ping", async (ISocketManager caller) =>
{
Console.WriteLine("ping");
await caller.Send("ping");
});
await builder.Build().StartAsync();
Connecting as Client
var connectionManager = host.Services.GetRequiredService<IConnectionManager>();
var discoveries = await connectionManager.Discover();
var found = discoveries.FirstOrDefault();
if (found != null)
{
var connection = await connectionManager.ConnectTo(found.Address, found.Port);
await connection.Send("testdata", new TestObject { Id = 3, Name = "Test" });
}
Full Example with DI and Logging
var builder = Host.CreateDefaultBuilder(args);
builder.AddSocketCommand(sb =>
{
sb.WithAESEncryption()
.With7ZipCompression()
.WithUdpDiscovery()
.WithCommand("ping", async (ISocketManager caller) =>
{
Console.WriteLine("ping");
await caller.Send("ping");
})
.WithCommand("testdata", async (TestObject obj, ILogger<TestObject> logger) =>
{
logger.LogInformation("Received: {Id} - {Name}", obj.Id, obj.Name);
});
});
await builder.Build().StartAsync();
π§© Customization
You can plug in your own compression or encryption strategies:
builder.AddSocketCommand()
.WithCompression<CustomCompressor>()
.WithEncryption<CustomEncryptor>();
Implement:
ISocketMessageCompressor
ISocketMessageEncryption
and register them via generics or manual DI.
π οΈ Requirements
- .NET 8
- Works in console apps, Windows services, and ASP.NET Core projects
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
-
net8.0
NuGet packages (2)
Showing the top 2 NuGet packages that depend on SocketCommand.Abstractions:
Package | Downloads |
---|---|
SocketCommand.Hosting
Hosting for socket command. |
|
SocketCommand.Compression.7Zip
7Zip compression for SocketCommand. |
GitHub repositories
This package is not used by any popular GitHub repositories.