IPC Broker (Tokio-based)
A lightweight inter-process communication (IPC) broker built with Tokio and Rust. It provides RPC, publish/subscribe eventing, and supports both TCP and Unix domain sockets for Linux and macOS, and both TCP and Named Pipes for Windows.
✨ Features
-
Dual transport support
- TCP (
127.0.0.1:5123) - Unix socket (
/tmp/ipc_broker.sock) - Named Pipes (
\\.\pipe\ipc_broker)
- TCP (
-
RPC calls
- Clients can call registered objects exposed by workers.
- Responses are automatically routed back to the original caller.
-
Object registration
- Workers can register named objects.
-
Pub/Sub
- Clients can subscribe to topics and receive published events.
-
Actor-based connection handling
- Each connection runs as an async actor.
- Read/write are decoupled through channels for maximum concurrency.
🧩 Architecture Overview
+-------------+ +-------------+ +-------------+
| Client | <----> | Broker | <----> | Worker |
|-------------| |-------------| |-------------|
| RPC calls | | Routes RPCs | | Exposes RPC |
| Pub/Sub | | Routes Pubs | | Handles req |
+-------------+ +-------------+ +-------------+
- Broker – Routes all communication between clients and workers.
- Worker – Registers objects and executes requested methods.
- Client – Invokes remote methods, publishes events, or subscribes to topics.
🚀 Getting Started (Development)
1. Run the Broker
The broker will listen on:
- TCP:
127.0.0.1:5123 - Unix socket:
/tmp/ipc_broker.sock(on Linux/macOS) - Named pipe:
\\.\pipe\ipc_broker(on Windows)
2. Run a Worker
use async_trait;
use ;
use ;
use Value;
;
async
3. Run a Client
use IPCClient;
use ;
use Value;
async
4. Publish Events
use IPCClient;
use Value;
async
5. Subscribe to an Event
use IPCClient;
async
6. Use the rob Command-Line Tool
The rob utility is a helper CLI for interacting with the broker.
🧪 Syntax
| Command | Description |
|---|---|
call |
Perform an RPC call and wait for a response |
send |
Publish an event to a topic |
listen |
Subscribe to a topic and listen for events |
🧪 Examples
🧩 Example 1 – RPC Call
Call a registered worker method:
Explanation:
{ii}means a map with keysaandb, both integers.- The arguments
a 10 b 32correspond to the values.
Expected Output:
Result:
Map:
sum :: 42
📢 Example 2 – Publish an Event
Publish a message to subscribers:
Signature s = string argument
Publishes a temperature event with the value "25.6°C".
📢 Example 3 – Subscribe to a Topic
Listen for published events:
Output:
Listening for: object=sensor method=temperature. Press ctrl+c to exit.
Result:
"25.6°C"
🧰 Signature Syntax Reference
| Symbol | Type | Example | Description |
|---|---|---|---|
s |
String | s "hello" |
Text value |
i |
Integer | i 42 |
64-bit integer |
n |
Null | n |
JSON null/ No parameter |
{ ... } |
Map | {is} key 123 value "text" |
Key-value pairs |
( ... ) |
Array | (sss) "one" "two" "three" |
List of values |
Examples:
# Map example
# Array example
)
🛠 Building
The resulting binaries will be placed in target/release/.
🪟 Platform Notes
| Platform | Supported Transports |
|---|---|
| Linux/macOS | TCP + Unix socket |
| Windows | TCP + Named Pipe |
📄 License
MIT License © 2025