ZeroMQ
ZeroMQ is MAGPIE’s core direct transport for Python, C++, and MicroPython. It needs no broker and works well on localhost, inside one process, or across a controlled network. The MicroPython implementation speaks ZMTP directly over TCP without requiring libzmq on the board.
Endpoints
| Endpoint | Use |
|---|---|
tcp://*:5555 | Bind on all interfaces |
tcp://127.0.0.1:5555 | Connect on the same host |
tcp://192.168.1.20:5555 | Connect over a LAN |
inproc://pipeline | Communicate within one process |
One side binds and the other connects. In Python and MicroPython readers, set bind=False when connecting. MicroPython supports tcp:// endpoints, not inproc://. Do not expose an unauthenticated bind endpoint to an untrusted network.
Streaming
- Python
- C++
- MicroPython
from luxai.magpie.transport import ZmqStreamWriter, ZmqStreamReader
writer = ZmqStreamWriter("tcp://*:5555")
reader = ZmqStreamReader("tcp://127.0.0.1:5555", topic=["robot/"], bind=False)
writer.write({"state": "ready"}, topic="robot/status")
value, topic = reader.read(timeout=2.0)
#include <magpie/frames/primitive_frames.hpp>
#include <magpie/transport/zmq_stream_reader.hpp>
#include <magpie/transport/zmq_stream_writer.hpp>
magpie::ZmqStreamWriter writer("tcp://*:5555");
magpie::ZmqStreamReader reader("tcp://127.0.0.1:5555", "robot/");
writer.write(magpie::StringFrame("ready"), "robot/status");
from luxai.magpie.transport.zmq import ZmqStreamWriter
writer = ZmqStreamWriter("tcp://*:5555", delivery="latest")
await writer.start()
await writer.wait_connected(timeout=10)
await writer.write({"state": "ready"}, "robot/status")
await writer.close()
A Python or C++ reader connects to the board's printed IP address. Reverse the ownership with ZmqStreamReader(..., bind=True) when the board should receive a desktop stream.
RPC
Use ZMQRpcRequester/ZMQRpcResponder in Python and ZmqRpcRequester/ZmqRpcResponder in C++ and MicroPython. The responder normally binds; requesters connect.
server = ZMQRpcResponder("tcp://*:5556")
client = ZMQRpcRequester("tcp://127.0.0.1:5556")
The equivalent asynchronous MicroPython service is:
from luxai.magpie.transport.zmq import ZmqRpcResponder
server = ZmqRpcResponder("tcp://*:5556")
await server.start()
while True:
await server.respond(handler=handle_request, timeout=1)
Deployment notes
- Prefer fixed ports and explicit firewall rules.
- Use DNS names or discovery instead of embedding changing IP addresses.
- A bind address of
*listens on every network interface; use it intentionally. - ZeroMQ is not a replacement for authentication or encryption. Place it on a trusted network or add an appropriate security layer.
- For cloud-to-robot communication behind NAT, MQTT or WebRTC signaling is usually easier operationally.
Browse the runnable Python ZeroMQ examples, C++ ZeroMQ examples, or MicroPython examples.