MIP-Client-rust
Rust client for the MIP (MSIP) protocol with async support.
Server implementation: MIP Server
Part of the MIP Client family:
- TypeScript: @mip-client/ts
- Python: mip-client-python
- Rust: mip-client (this package)
Features
- Async/Await - Built on Tokio for high-performance async I/O
- Auto-reconnection - Automatic reconnection with configurable retry logic
- Event-driven - Callback-based API for handling messages and events
- Type-safe - Full Rust type safety with proper error handling
- Ping/Pong - Configurable heartbeat interval
Installation
Add to your Cargo.toml:
[]
= "1.0"
= { = "1", = ["full"] }
Or via cargo:
Quick Start
use ;
async
API Reference
MIPClientOptions
| Option | Type | Default | Description |
|---|---|---|---|
client_id |
String | "" | Client identifier (sent in HELLO frame) |
host |
String | "127.0.0.1" | Server host address |
port |
u16 | 9000 | Server port number |
auto_reconnect |
bool | true | Auto-reconnect on disconnect |
reconnect_delay_ms |
u64 | 3000 | Reconnect delay in ms |
max_reconnect_attempts |
u32 | 10 | Max reconnect attempts (0 = infinite) |
ping_interval_ms |
u64 | 0 | Ping interval in ms (0 = disabled) |
Methods
| Method | Description |
|---|---|
connect() |
Connect to the MIP server |
disconnect() |
Disconnect from the server |
subscribe(topic, require_ack) |
Subscribe to a topic |
unsubscribe(topic, require_ack) |
Unsubscribe from a topic |
publish(topic, message, flags) |
Publish a message to a topic |
ping() |
Send a ping to the server |
is_connected() |
Check if the client is connected |
Events
| Event | Callback Type | Description |
|---|---|---|
on_connect |
Fn() |
Called when connected |
on_disconnect |
Fn() |
Called when disconnected |
on_reconnecting |
Fn(u32) |
Called on reconnection attempt |
on_message |
Fn(MIPMessage) |
Called on any message |
on_event |
Fn(MIPMessage) |
Called on EVENT frames |
on_ack |
Fn(u64) |
Called when ACK received |
on_pong |
Fn() |
Called when PONG received |
on_error |
Fn(MIPError) |
Called on error |
on_frame |
Fn(Header, Vec<u8>) |
Called on any raw frame |
Frame Flags
use FrameFlags;
NONE // No flags
ACK_REQUIRED // Request acknowledgment
COMPRESSED // Payload is compressed
URGENT // Urgent message
Protocol
The MIP protocol uses a binary frame format with a 24-byte header:
| Field | Size | Description |
|---|---|---|
| Magic | 4 bytes | "MSIP" |
| Version | 1 byte | Protocol version (1) |
| Flags | 1 byte | Frame flags |
| Frame Type | 2 bytes | Type of frame |
| Message Kind | 2 bytes | Kind of message |
| Reserved | 2 bytes | Reserved for future use |
| Payload Length | 4 bytes | Length of payload |
| Message ID | 8 bytes | Unique message identifier |
License
MIT