HRpc 1.1.2

dotnet add package HRpc --version 1.1.2
                    
NuGet\Install-Package HRpc -Version 1.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="HRpc" Version="1.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HRpc" Version="1.1.2" />
                    
Directory.Packages.props
<PackageReference Include="HRpc" />
                    
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 HRpc --version 1.1.2
                    
#r "nuget: HRpc, 1.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 HRpc@1.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=HRpc&version=1.1.2
                    
Install as a Cake Addin
#tool nuget:?package=HRpc&version=1.1.2
                    
Install as a Cake Tool

HRpc

HRpc is a lightweight .NET library for event-driven TCP and Named Pipe messaging.

Install

dotnet add package HRpc

Supported Frameworks

  • net48
  • net6.0
  • net7.0
  • net9.0

Message Format

HRpc exchanges newline-delimited JSON envelopes:

{ "eventName": "MyEvent", "payload": "Any string payload" }

API Overview

HRpc provides unified Connection and Server classes for both TCP and Named Pipe transports. Select the transport type using the TransportType property.

Transport Types

  • TransportType.Tcp: TCP/IP networking
  • TransportType.Pipe: Local Named Pipes (same machine)

Quick Start (Client)

TCP Client

using TcpEventFramework.Core;

var connection = new Connection();
connection.TransportType = TransportType.Tcp;

await connection.ConnectAsync("127.0.0.1:9000");

connection.MessageReceived += (sender, e) =>
{
    Console.WriteLine($"Received: {e.Message.EventName} - {e.Message.Payload}");
};

await connection.SendAsync(new EventMessage("Hello", "World"));
await connection.CloseAsync();

Named Pipe Client

using TcpEventFramework.Core;

var connection = new Connection();
connection.TransportType = TransportType.Pipe;

await connection.ConnectAsync("my-hrpc-pipe");

connection.MessageReceived += (sender, e) =>
{
    Console.WriteLine($"Received: {e.Message.EventName} - {e.Message.Payload}");
};

await connection.SendAsync(new EventMessage("Hello", "World"));
await connection.CloseAsync();

Quick Start (Server)

TCP Server

using TcpEventFramework.Core;

var server = new Server();
server.TransportType = TransportType.Tcp;

server.MessageReceived += (sender, e) =>
{
    Console.WriteLine($"Received: {e.Message.EventName} - {e.Message.Payload}");
};

await server.StartAsync("9000");

Named Pipe Server

using TcpEventFramework.Core;

var server = new Server();
server.TransportType = TransportType.Pipe;

server.MessageReceived += (sender, e) =>
{
    Console.WriteLine($"Received: {e.Message.EventName} - {e.Message.Payload}");
};

await server.StartAsync("my-hrpc-pipe");

Advanced Usage

EventDispatcher for Request-Response Patterns

Use EventDispatcher to subscribe to specific events and emit messages.

using TcpEventFramework.Core;
using TcpEventFramework.Models;

var dispatcher = new EventDispatcher();

var connection = new Connection();
connection.TransportType = TransportType.Tcp;

await connection.ConnectAsync("127.0.0.1:9000");

// Subscribe to "Ping" events
using var subscription = dispatcher.Subscribe(connection, "Ping", msg =>
{
    Console.WriteLine($"Ping received: {msg.Payload}");

    // Respond with "Pong"
    Task.Run(() => dispatcher.Emit(connection, new EventMessage("Pong", "Response")));
});

// Send a ping
await dispatcher.Emit(connection, new EventMessage("Ping", "Hello"));

await connection.CloseAsync();

Error Handling

Handle connection errors and invalid messages.

using TcpEventFramework.Core;

var connection = new Connection();
connection.TransportType = TransportType.Tcp;

connection.Connected += (sender, e) => Console.WriteLine("Connected!");
connection.Disconnected += (sender, e) => Console.WriteLine("Disconnected!");
connection.ErrorOccurred += (sender, e) => Console.WriteLine($"Error: {e.Message}");

try
{
    await connection.ConnectAsync("127.0.0.1:9000");
    // Use connection...
}
catch (Exception ex)
{
    Console.WriteLine($"Connection failed: {ex.Message}");
}
finally
{
    await connection.CloseAsync();
}

Full Client-Server Example

Server
using TcpEventFramework.Core;

var server = new Server();
server.TransportType = TransportType.Tcp;

server.MessageReceived += async (sender, e) =>
{
    Console.WriteLine($"Server received: {e.Message.EventName} - {e.Message.Payload}");

    // Echo back
    if (sender is Server srv)
    {
        // Note: Server doesn't have SendAsync; messages are handled via events
        // For response, you might need to use a separate connection or custom logic
    }
};

await server.StartAsync("9000");
Console.WriteLine("Server started on port 9000");
Client
using TcpEventFramework.Core;
using TcpEventFramework.Models;

var client = new Connection();
client.TransportType = TransportType.Tcp;

client.MessageReceived += (sender, e) =>
{
    Console.WriteLine($"Client received: {e.Message.EventName} - {e.Message.Payload}");
};

await client.ConnectAsync("127.0.0.1:9000");
Console.WriteLine("Client connected");

await client.SendAsync(new EventMessage("Test", "Hello from client!"));

await Task.Delay(1000); // Wait for response

await client.CloseAsync();

Error Handling

  • ConnectAsync(...) throws on failure and also raises ErrorOccurred.
  • Invalid message payloads raise ErrorOccurred.
  • EventDispatcher.Subscribe(...) returns IDisposable; dispose it to unsubscribe.
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  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 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. 
.NET Framework net48 is compatible.  net481 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.1.2 103 2/19/2026
1.1.1 99 2/19/2026
1.1.0 99 2/19/2026
1.0.2 101 2/17/2026
1.0.1 105 2/17/2026