ZeroMQ Wrapper for ThinBASIC
High-performance messaging for ThinBASIC. Choose full native #INCLUDE APIs
or the optional USES "ZeroMQ" SDK module — PUB/SUB, REQ/REP, CURVE, PLAIN, Poll, and more.
x86 only. ThinBASIC is a 32-bit process — load only Library\x86
libzmq.dll / libsodium.dll.
Do not use x64 builds from FreeBasicZMQ / PureBasicZMQ.
You can still talk to x64 peers over tcp:// (wire protocol is architecture-independent).
Do not mix #INCLUDE Core files with USES "ZeroMQ"
Core\ZeroMQ.inc · full procedural + Type wrapper
LibPath.inc (CWD)$ZMQ_*#INCLUDE Once ".\Core\ZeroMQ.inc"
#INCLUDE Once ".\Core\ZeroMQWrapper.inc"
USES "ZeroMQ" · thinBasic_ZeroMQ.dll
ZmqLibraryInitZmqLibraryInit(path)SDK\C\build_pelles.bat%ZMQ_*PUB/SUB multipart, REQ/REP, PUSH/PULL (SDK), Weather JSON scenario, Poll, Proxy, Monitor.
LibZmqContext, LibZmqSocket, … with renamed methods where ThinBASIC reserved words conflict.
CURVE end-to-end REQ/REP, PLAIN + in-process ZAP, Z85 helpers, CurveKeypair.
thinBasic_ZeroMQ.dll — install to C:\thinBasic\Lib\, keywords with parentheses.
Enums, Runtime, Context, Socket, Msg, Poll, Proxy, Security, Helper — umbrella ZeroMQ.inc.
Bundled under Library\x86. Type features need ThinBASIC 1.4.0+.
Procedural · Module · SDK examples
| Script | Notes |
|---|---|
| PubServer / SubClient | PUB/SUB procedural · port 1689 · topic quotes |
| RepServer / ReqClient | REQ/REP procedural |
| Module\*.tbasic | Same patterns via ZeroMQWrapper.inc |
| Monitor · Thread · Proxy · Poll | Infrastructure & helpers |
| Curve · Plain · Z85 | Security end-to-end |
| Weather\* | Weather-style JSON PUB/SUB |
| SDK\C\examples\* | USES "ZeroMQ" — smoke, REQ/REP, PUB/SUB, CURVE, PUSH/PULL, multipart… |
ThinBASIC reserved words cannot be Type method names
| Procedural | Type method |
|---|---|
ZmqBind | SockBind |
ZmqSend / ZmqRecv | SockSend / SockRecv |
ZmqErrno | GetErrno |
ZmqPoll | DoPoll |
Subscribe before Connect · start Pub first · ~200 ms slow-joiner pause
Uses "CONSOLE"
#INCLUDE Once ".\Core\ZeroMQWrapper.inc"
Dim ZmqContextRec As LibZmqContext
Dim ZmqSocketRec As LibZmqSocket
Dim ZmqRuntimeRec As LibZmqRuntime
hContext = ZmqContextRec.NewCtx()
hSocket = ZmqSocketRec.NewSocket(hContext, $ZMQ_PUB)
Rc = ZmqSocketRec.SockBind(hSocket, "tcp://*:1689")
If Rc = 0 Then
Sleep 200
While %TRUE
lpszTopic = "quotes"
lpszSendMessage = "Bid:…,Ask:…"
ZmqSocketRec.SockSend(hSocket, StrPtr(lpszTopic), Len(lpszTopic), $ZMQ_SNDMORE)
ZmqSocketRec.SockSend(hSocket, StrPtr(lpszSendMessage), Len(lpszSendMessage), 0)
Sleep 100
Wend
End If
hSocket = ZmqSocketRec.NewSocket(hContext, $ZMQ_SUB)
ZmqSocketRec.SockSetsockopt(hSocket, $ZMQ_SUBSCRIBE, StrPtr("quotes"), Len("quotes"))
ZmqSocketRec.SockConnect(hSocket, "tcp://localhost:1689")
TopicBytes = ZmqSocketRec.SockRecv(hSocket, VarPtr(lpszTopicBuffer), SizeOf(lpszTopicBuffer), 0)
MessageBytes = ZmqSocketRec.SockRecv(hSocket, VarPtr(lpszRecvBuffer), SizeOf(lpszRecvBuffer), 0)
Printl(Left$(lpszRecvBuffer, MessageBytes))
Environment · library · SDK build
ThinBasicZMQ\Library\x86\
libzmq.dll
libsodium.dll
Native examples: interpreter + Library\x86 only.
cd SDK\C
build_pelles.bat
Copy thinBasic_ZeroMQ.dll to C:\thinBasic\Lib\
Clone the repo, use x86 libzmq, and start with native includes or the SDK module.