ZeroMQ Wrapper for FreeBASIC
High-performance messaging for FreeBASIC. PUB/SUB, REQ/REP, CURVE and PLAIN security, poll, proxy, and monitor — with both procedural samples and OOP Module twins.
PUB/SUB (multipart), REQ/REP, Weather scenario — plus Poll, Proxy, and Monitor helpers.
Each major sample has a procedural copy under Example/ and an OOP twin under Example/Module/.
Bundled DLL is CURVE-enabled. PLAIN + ZAP demo (admin/secret). Runtime check via zmq_has("curve").
zmq_has for ipc, curve, draft, pgm, and more. Symbols resolved once on open (Core/Symbols.bi).
LibZmqContext, LibZmqSocket, LibZmqRuntime — clean OOP-style façade over libzmq.
Library/x64 and Library/x86 for libzmq (+ libsodium when present). Prefer fbc64 for x64 builds.
Procedural under Example/ · OOP twins under Example/Module/
| Example | Pattern | Notes |
|---|---|---|
| Zmq / Has | Version / zmq_has | Smoke / capability probe |
| PubServer + SubClient | PUB/SUB multipart | Port 1689, topic quotes |
| Weather/* | PUB/SUB weather | Port 1692, simulated updates |
| ReqClient + RepServer | REQ/REP | Request–reply |
| Plain | PLAIN + ZAP | Port 1720, user admin / secret |
| Curve / CurveKeypair | CURVE | Needs zmq_has("curve")=1 |
| Poll / Proxy / Monitor | Infrastructure | Poll, steerable proxy, monitor |
| Z85 · Msg · Thread · Stopwatch | Helpers | Encode/decode, msg API, utilities |
Subscribe before Connect · start Pub first · ~200 ms slow-joiner pause
#Include "Core/Enums.bi"
#Include "Core/ZeroMQWrapper.bi"
Dim ZmqContextRec As LibZmqContext
Dim ZmqSocketRec As LibZmqSocket
Dim ZmqRuntimeRec As LibZmqRuntime
If LibZMQWrapper.DllOpen("libzmq.dll") Then
Dim Context As Any Ptr = ZmqContextRec.NewCtx()
Dim Socket As Any Ptr = ZmqSocketRec.Socket(Context, ZMQ_PUB)
Dim Rc As Long = ZmqSocketRec.Bind(Socket, "tcp://*:1689")
If Rc = 0 Then
Sleep(200) ' slow joiner
While 1
Dim topic As String = "quotes"
Dim msg As String = "Bid:…,Ask:…"
ZmqSocketRec.Send(Socket, StrPtr(topic), Len(topic), ZMQ_SNDMORE)
ZmqSocketRec.Send(Socket, StrPtr(msg), Len(msg), 0)
Sleep(100)
Wend
End If
End If
Dim Socket As Any Ptr = ZmqSocketRec.Socket(Context, ZMQ_SUB)
Dim sub As String = "quotes"
ZmqSocketRec.Setsockopt(Socket, ZMQ_SUBSCRIBE, StrPtr(sub), Len(sub))
ZmqSocketRec.Connect(Socket, "tcp://localhost:1689")
Dim buf As ZString * 256
Dim n As Long = ZmqSocketRec.Recv(Socket, @buf, SizeOf(buf), 0)
If n <> -1 Then Print(Left(buf, n))
Set the working directory to the package root that contains Core/, Example/, and Library/.
Examples load Library/x64/libzmq.dll or Library/x86/libzmq.dll (and libsodium when present) via Chdir.
Prefer fbc64.exe for x64 binaries so the x64 DLL is used.
Pub/Sub order: start Pub first → wait for bind (~200 ms) → start Sub → subscribers call ZMQ_SUBSCRIBE before Connect.
fbc Example/PubServer.bas -target win64
fbc Example/SubClient.bas -target win64
Environment · library path
FreeBasicZMQ/Library/x64/libzmq.dll
FreeBasicZMQ/Library/x86/libzmq.dll
(+ libsodium.dll when present)
Clone the repo, point at libzmq, and start with PUB/SUB or REQ/REP — procedural or Module style.