FreeBASIC · libzmq · Messaging

FreeBasicZMQ

ZeroMQ Wrapper for FreeBASIC

libzmq 4.3.6 API FreeBASIC 1.10.1+ x86 / x64 Procedural + Module CURVE-enabled MIT License

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.

Key Features

Messaging Patterns

PUB/SUB (multipart), REQ/REP, Weather scenario — plus Poll, Proxy, and Monitor helpers.

Procedural + Module

Each major sample has a procedural copy under Example/ and an OOP twin under Example/Module/.

CURVE & PLAIN

Bundled DLL is CURVE-enabled. PLAIN + ZAP demo (admin/secret). Runtime check via zmq_has("curve").

Capability Probe

zmq_has for ipc, curve, draft, pgm, and more. Symbols resolved once on open (Core/Symbols.bi).

Type Wrappers

LibZmqContext, LibZmqSocket, LibZmqRuntime — clean OOP-style façade over libzmq.

x86 & x64

Library/x64 and Library/x86 for libzmq (+ libsodium when present). Prefer fbc64 for x64 builds.

Examples

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

PUB / SUB Example

Subscribe before Connect · start Pub first · ~200 ms slow-joiner pause

Publisher (excerpt) fbc … -target win64
#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
Subscriber (excerpt) ZMQ_SUBSCRIBE before Connect
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))

How to Run Examples

1

Set the working directory to the package root that contains Core/, Example/, and Library/.

2

Examples load Library/x64/libzmq.dll or Library/x86/libzmq.dll (and libsodium when present) via Chdir.

3

Prefer fbc64.exe for x64 binaries so the x64 DLL is used.

4

Pub/Sub order: start Pub first → wait for bind (~200 ms) → start Sub → subscribers call ZMQ_SUBSCRIBE before Connect.

Build

fbc Example/PubServer.bas -target win64
fbc Example/SubClient.bas -target win64

Get Started

Environment · library path

Environment

  • Windows 7+
  • FreeBASIC 1.10.1+ (recommend)
  • libzmq 4.3.6 API constants
  • Tested under Windows 10/11

Library Path

FreeBasicZMQ/Library/x64/libzmq.dll
FreeBasicZMQ/Library/x86/libzmq.dll
(+ libsodium.dll when present)

Message from FreeBASIC

Clone the repo, point at libzmq, and start with PUB/SUB or REQ/REP — procedural or Module style.