ZeroMQ Wrapper for PureBasic
Bring high-performance messaging to PureBasic. Bind, connect, publish, request, push, and more — with module wrappers, multipart frames, Curve security, and complete pattern examples.
PUB/SUB, REQ/REP, PUSH/PULL, DEALER/ROUTER, PAIR, STREAM — with low-level and Module examples.
SendFrames, SendStrings, RecvAllFrames, HasRcvMore — clean multi-part message helpers.
ZmqContext, ZmqSocket, ZmqRuntime — structured PureBasic modules for cleaner code.
CURVE, PLAIN, Z85 encoding — secure transports when your libzmq build supports them.
Socket polling, proxy helpers, socket monitor events, and capability probes via zmq_has.
Place libzmq.dll under Library/x64 or Library/x86 — examples resolve path from the processor.
Low-level and Module examples for every classic pattern
| Pattern | Low-level | Module | Port |
|---|---|---|---|
| PUB / SUB | PubServer · SubClient | Module/PubServer · SubClient | 1689 |
| REQ / REP | ReqClient · RepServer | Module/ReqClient · RepServer | 1700 |
| PUSH / PULL | PushServer · PullClient | Module/PushServer · PullClient | 1701 |
| DEALER / ROUTER | DealerClient · RouterServer | Module/DealerClient · RouterServer | 1702 |
| PAIR | PairClient · PairServer | Module/PairClient · PairServer | 1703 |
| STREAM | StreamClient · StreamServer | Module/StreamClient · StreamServer | 1704 |
| Multipart | Frames.pb | Module/Frames.pb | 1705 |
| Monitor | Monitor.pb | Module/Monitor.pb | 1700 + inproc |
Also: Has · Poll · Proxy · Z85 · Curve* · Plain · Msg · Thread · Stopwatch · Weather
Publisher is send-only — do not call Recv on a ZMQ_PUB socket
IncludeFile "../../Core/Enums.pbi"
IncludeFile "../../Core/ZeroMQWrapper.pbi"
UseModule ZeroMQWrapper
Define Context.i = ZmqContext::New()
Define Socket.i = ZmqSocket::Socket(Context, #ZMQ_PUB)
Define Rc.i = ZmqSocket::Bind(Socket, "tcp://*:1689")
If Rc <> 0
PrintN("Bind failed: " + ZmqRuntime::Strerror(ZmqRuntime::Errno()))
Else
Delay(200) ; slow joiner
While 1
Define topic.s = "quotes"
Define msg.s = "Bid:" + Random(9000, 1000)
ZmqSocket::Send(Socket, topic, Len(topic), #ZMQ_SNDMORE)
ZmqSocket::Send(Socket, msg, Len(msg), 0)
Delay(100)
Wend
EndIf
Define Socket.i = ZmqSocket::Socket(Context, #ZMQ_SUB)
Define sub.s = "quotes"
; Subscribe before connect to reduce missed early messages
ZmqSocket::Setsockopt(Socket, #ZMQ_SUBSCRIBE, sub, Len(sub))
ZmqSocket::Connect(Socket, "tcp://localhost:1689")
Define *buf = AllocateMemory(256)
Define n.i = ZmqSocket::Recv(Socket, *buf, MemorySize(*buf), 0)
; Use Recv byte count — ZMQ payloads are not null-terminated
PrintN(PeekS(*buf, n, #PB_UTF8))
FreeMemory(*buf)
libzmq conventions apply
0 success, -1 failure-10 as failureDefine Rc.i = ZmqSocket::Bind(Socket, addr)
If Rc <> 0
PrintN("Bind failed: " +
ZmqRuntime::Strerror(
ZmqRuntime::Errno()))
EndIf
Environment · library path · build
Place libzmq.dll under:
PureBasicZMQ/Library/x64/
PureBasicZMQ/Library/x86/
Requires PureBasic Compiler. Tested under Windows 11. Include Core/Enums.pbi and Core/ZeroMQWrapper.pbi.
Clone the repo, drop in libzmq, and start with PUB/SUB or REQ/REP — module or low-level, your choice.