NTDLS.ReliableMessaging Usage
Lightweight TCP/IP inter-process communication and RPC in C# with notifications, queries, compression and encryption.
NTDLS.ReliableMessaging
What it is. A lightweight, high-performance TCP/IP messaging library for C#. Once connected, peers exchange two kinds of messages: fire-and-forget notifications (IRmNotification) and request/reply queries (IRmQuery<TReply>). Handlers can be convention-based (a class implementing IRmMessageHandler) or event-based. Optional built-in compression (Deflate or Brotli) and pluggable encryption round out the toolkit; CRC checks are applied to every packet automatically.
When to reach for it. You need a simple RPC backbone between your own services - backend to UI, service to service - without adopting gRPC or a message broker. It has been used as the communications layer for instant messaging, file transfer, proxy/tunneling and even a relational database server. Skip it if you need cross-language clients or a published wire protocol; this is designed for .NET-to-.NET talk.
Getting started
Define your message types:
public class MyNotification : IRmNotification
{
public string Message { get; set; }
public MyNotification(string message)
{
Message = message;
}
}
public class MyQuery : IRmQuery<MyQueryReply>
{
public string Message { get; set; }
public MyQuery(string message)
{
Message = message;
}
}
public class MyQueryReply : IRmQueryReply
{
public string Message { get; set; }
public MyQueryReply(string message)
{
Message = message;
}
}
Start a server with a convention-based handler whose method signatures match your message types:
var server = new RmServer();
server.AddHandler(new HandlerMethods());
server.Start(31254);
internal class HandlerMethods : IRmMessageHandler
{
public void MyNotificationReceived(RmContext context, MyNotification notification)
{
Console.WriteLine($"Server received notification: {notification.Message}");
}
public MyQueryReply MyQueryReceived(RmContext context, MyQuery query)
{
return new MyQueryReply("This is the query reply from the server.");
}
}
Then connect a client, send notifications, and issue a query that blocks until the reply arrives:
var client = new RmClient();
client.Connect("localhost", 31254);
client.Notify(new MyNotification("Hello from the client."));
var reply = client.Query(new MyQuery("What time is it?"));
Console.WriteLine($"Client received query reply: '{reply.Message}'");
Async variants NotifyAsync() and QueryAsync() are available, and compression/encryption attach via SetCompressionProvider() / SetCryptographyProvider() on both ends.
NuGet: NTDLS.ReliableMessaging