Sphere10.Framework.Communications 3.1.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Sphere10.Framework.Communications --version 3.1.2
                    
NuGet\Install-Package Sphere10.Framework.Communications -Version 3.1.2
                    
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="Sphere10.Framework.Communications" Version="3.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Sphere10.Framework.Communications" Version="3.1.2" />
                    
Directory.Packages.props
<PackageReference Include="Sphere10.Framework.Communications" />
                    
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 Sphere10.Framework.Communications --version 3.1.2
                    
#r "nuget: Sphere10.Framework.Communications, 3.1.2"
                    
#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 Sphere10.Framework.Communications@3.1.2
                    
#: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=Sphere10.Framework.Communications&version=3.1.2
                    
Install as a Cake Addin
#tool nuget:?package=Sphere10.Framework.Communications&version=3.1.2
                    
Install as a Cake Tool

📡 Sphere10.Framework.Communications

Multi-protocol networking and RPC framework providing JSON-RPC servers/clients, anonymous pipes, TCP endpoints, WebSockets, and protocol channel abstractions.

📦 Installation

dotnet add package Sphere10.Framework.Communications

🏗️ Core Architecture

IEndPoint Interface

The IEndPoint interface abstracts communication endpoints for message-based protocols:

public interface IEndPoint {
    string GetDescription();
    ulong GetUID();
    IEndPoint WaitForMessage();
    EndpointMessage ReadMessage();
    void WriteMessage(EndpointMessage message);
    bool IsOpened();
    void Start();
    void Stop();
}

Implementations:

  • TcpEndPoint - TCP socket communication
  • TcpEndPointListener - TCP server that accepts connections
  • AnonymousPipeEndpoint - Inter-process pipe communication

JSON-RPC Framework

The RPC system uses attributes to define remote-callable services:

Attribute Target Description
[RpcAPIService("name")] Class Defines a service namespace
[RpcAPIMethod] Method Marks method as remotely callable
[RpcAPIMethod("alias")] Method Marks method with custom RPC name
[RpcAPIArgument("name")] Parameter Maps parameter to JSON field name

🔧 JSON-RPC Server

Create a JSON-RPC server with TCP endpoint:

using Sphere10.Framework.Communications.RPC;

// Define service
[RpcAPIService("math")]
public class MathService {
    [RpcAPIMethod]
    public int Add(int a, int b) => a + b;
    
    [RpcAPIMethod]
    public uint AddUnsigned(uint a, uint b) => a + b;
    
    [RpcAPIMethod]
    public float Multiply(float a, float b) => a * b;
}

// Create server
var endpoint = new TcpEndPointListener(port: 8080);
var config = new JsonRpcConfig();
var server = new JsonRpcServer(endpoint, config);

// Register services
var mathService = new MathService();
config.ApiService.AddApi(mathService);

// Start server
server.Start();

// Handle new clients
server.OnNewClient += (handler) => {
    Console.WriteLine($"Client connected: {handler}");
};

JsonRpcConfig

Configuration for JSON-RPC servers and clients:

var config = new JsonRpcConfig {
    ConnectionMode = JsonRpcConfig.ConnectionModeEnum.Persistent,  // or Pulsed
    Logger = new ConsoleLogger()
};

🔧 JSON-RPC Client

Connect to a JSON-RPC server:

using Sphere10.Framework.Communications.RPC;

// Connect to server
var endpoint = new TcpEndPoint("localhost", 8080);
var config = new JsonRpcConfig();
var client = new JsonRpcClient(endpoint, config);

// Make RPC calls using batch descriptor
var batch = new ApiBatchCallDescriptor();
batch.AddCall<int>("math.add", new { a = 5, b = 3 });
batch.AddCall<float>("math.multiply", new { a = 2.5f, b = 4.0f });

object[] results = client.RemoteCall(batch);
int sum = (int)results[0];        // 8
float product = (float)results[1]; // 10.0

🔧 ApiService - Service Registration

The ApiService class manages RPC method bindings:

var apiService = new ApiService();

// Add service instance
var mathService = new MathService();
apiService.AddApi(mathService);

// Remove service
apiService.RemoveApi(mathService);

// Check if instance is registered
bool isRegistered = apiService.IsApi(mathService);

Service with Custom Parameter Names

[RpcAPIService("strings")]
public class StringService {
    [RpcAPIMethod]
    public string Concat(
        [RpcAPIArgument("first")] string text1,
        [RpcAPIArgument("second")] string text2) 
        => text1 + text2;
    
    [RpcAPIMethod("explicit_args")]
    public void ExplicitArguments([RpcAPIArgument("arg1")] uint value) {
        // Custom method name and parameter name
    }
}

Complex Types and Collections

public class TestObject {
    public int iVal;
    public string sVal;
    public float[] fArray;
    [JsonConverter(typeof(ByteArrayHexConverter))]
    public byte[] bytesArray;  // Serialized as hex string
}

[RpcAPIService("objects")]
public class ObjectService {
    [RpcAPIMethod]
    public TestObject GetTestObject(TestObject input) {
        return new TestObject {
            iVal = input.iVal + 1,
            sVal = input.sVal + "_processed"
        };
    }
    
    [RpcAPIMethod]
    public TestObject[] GetTestObjectArray(TestObject input) {
        return new[] { input, input };
    }
}

🔗 Anonymous Pipes

For inter-process communication:

using Sphere10.Framework.Communications;

// Server side - spawn child process with pipe handles
var serverPipe = AnonymousPipe.ToChildProcess(
    processPath: "child.exe",
    arguments: "",
    argInjectorFunc: (args, readHandle, writeHandle) => 
        $"{args} --read={readHandle} --write={writeHandle}"
);

await serverPipe.Open();
await serverPipe.TrySendString("Hello from parent");
var response = await serverPipe.ReceiveString(CancellationToken.None);

// Client side - connect using handles from arguments
var clientPipe = AnonymousPipe.FromChildProcess(
    new AnonymousPipeEndpoint(readHandle, writeHandle)
);

await clientPipe.Open();
var message = await clientPipe.ReceiveString(CancellationToken.None);
await clientPipe.TrySendString("Hello from child");

AnonymousPipe Events

pipe.ReceivedString += (message) => Console.WriteLine($"Received: {message}");
pipe.SentString += (message) => Console.WriteLine($"Sent: {message}");

🔗 TCP Endpoints

TcpEndPoint - Client Connection

using Sphere10.Framework.Communications.RPC;

var endpoint = new TcpEndPoint("192.168.1.100", 8080);
endpoint.MaxMessageSize = 8192;  // Default: 4096

endpoint.Start();

// Send message
endpoint.WriteMessage(new EndpointMessage("Hello Server"));

// Receive message
var response = endpoint.ReadMessage();
Console.WriteLine(response.ToSafeString());

endpoint.Stop();

TcpEndPointListener - Server

var listener = new TcpEndPointListener(8080);
listener.Start();

// Wait for client connection
IEndPoint clientEndpoint = listener.WaitForMessage();
Console.WriteLine($"Client connected: {clientEndpoint.GetDescription()}");

// Communicate with client
var message = clientEndpoint.ReadMessage();
clientEndpoint.WriteMessage(new EndpointMessage("Response"));

🔗 Protocol Channels

Abstract base for bidirectional communication:

using Sphere10.Framework.Communications;

public abstract class ProtocolChannel {
    public ProtocolChannelState State { get; }
    public CommunicationRole Initiator { get; }
    
    public Task Open();
    public Task Close();
    public bool IsConnectionAlive();
    
    public Task<bool> TrySendBytes(ReadOnlyMemory<byte> bytes, CancellationToken ct);
    public Task<byte[]> ReceiveBytes(CancellationToken ct);
}

States: Closed, Opening, Open, Closing

🛡️ Security Policies

The TcpSecurityPolicies class provides connection-level security:

// Validate connection count
TcpSecurityPolicies.ValidateConnectionCount(
    TcpSecurityPolicies.MaxConnecitonPolicy.ConnectionOpen);

// Monitor for potential attacks
TcpSecurityPolicies.MonitorPotentialAttack(
    TcpSecurityPolicies.AttackType.ConnectionFlod, 
    clientEndpoint);

// Validate JSON message quality
TcpSecurityPolicies.ValidateJsonQuality(messageBytes, bytesRead);

📁 Project Structure

Directory Description
RPC/ JSON-RPC server, client, attributes, service management
EndPoint/ IEndPoint interface and TCP implementations
Pipes/ Anonymous pipe communication
TCP/ TCP channel implementation
UDP/ UDP communication
WebSockets/ WebSocket protocol support
DataSource/ Data source abstractions for protocols

✅ Best Practices

  • Stateless Services - Design RPC services as stateless for scalability
  • Exception Handling - Exceptions are serialized as JSON-RPC error responses
  • Thread Safety - RPC service methods should be thread-safe
  • Connection Mode - Use Persistent for frequent calls, Pulsed for occasional
  • Message Size - Configure MaxMessageSize for your payload requirements

⚖️ License

Distributed under the MIT License.

See the LICENSE file for full details. More information: MIT License

👤 Author

Herman Schoenfeld - Software Engineer

Anonymous-pipe sends wait for the preceding message to drain on Windows. Other platforms write through the pipe without invoking the Windows-only drain API. WebSocket close handling rejects unsupported communication-role enum values explicitly.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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 (1)

Showing the top 1 NuGet packages that depend on Sphere10.Framework.Communications:

Package Downloads
Sphere10.Framework.Application

Application framework and lifecycle management for Sphere10 Framework-based apps. Provides dependency injection integration, settings persistence, command-line argument parsing, product/version metadata, and builder-based startup/shutdown hooks.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.2.0 330 11/24/2026
3.2.0-ci.186.45519021075.1 113 11/25/2026
3.2.0-ci.185.45437957423.1 126 11/24/2026
3.2.0-ci.184.45433825651.1 122 11/24/2026
3.2.0-ci.179.45429051159.1 124 11/24/2026
3.2.0-ci.176.45423889482.1 123 11/24/2026
3.2.0-ci.175.45417619940.1 119 11/24/2026
3.2.0-ci.174.45412668816.1 124 11/24/2026
3.2.0-ci.173.45375449609.1 123 11/24/2026
3.2.0-ci.171.45374063975.1 117 11/24/2026
3.2.0-ci.169.45350717665.1 120 11/24/2026
3.2.0-ci.168.45166918016.1 149 11/23/2026
3.2.0-ci.163.43664782937.1 76 11/15/2026
3.2.0-ci.160.43660265392.1 68 11/15/2026
3.2.0-ci.159.43537748063.1 70 11/14/2026
3.2.0-ci.158.43536665157.1 73 11/14/2026
3.2.0-ci.157.43350632870.1 74 11/13/2026
3.2.0-ci.156.43233095581.1 72 11/12/2026
3.1.2 163 9/9/2026
3.1.1 139 9/8/2026
Loading failed