ThinBASIC · libzmq · x86

ThinBasicZMQ

ZeroMQ Wrapper for ThinBASIC

libzmq ThinBASIC 1.14+ x86 only Native + SDK Type wrapper MIT License

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).

Two Ways to Call ZeroMQ

Do not mix #INCLUDE Core files with USES "ZeroMQ"

Native

Core\ZeroMQ.inc · full procedural + Type wrapper

  • Full coverage
  • libzmq via LibPath.inc (CWD)
  • No build — includes only
  • Constants: $ZMQ_*
#INCLUDE Once ".\Core\ZeroMQ.inc"
#INCLUDE Once ".\Core\ZeroMQWrapper.inc"

SDK Module

USES "ZeroMQ" · thinBasic_ZeroMQ.dll

  • Core subset + ZmqLibraryInit
  • Path via ZmqLibraryInit(path)
  • Build: SDK\C\build_pelles.bat
  • Constants: %ZMQ_*
SDK/C README →

Key Features

Messaging Patterns

PUB/SUB multipart, REQ/REP, PUSH/PULL (SDK), Weather JSON scenario, Poll, Proxy, Monitor.

Procedural + Type

LibZmqContext, LibZmqSocket, … with renamed methods where ThinBASIC reserved words conflict.

CURVE & PLAIN

CURVE end-to-end REQ/REP, PLAIN + in-process ZAP, Z85 helpers, CurveKeypair.

SDK Module

thinBasic_ZeroMQ.dll — install to C:\thinBasic\Lib\, keywords with parentheses.

Structured Core

Enums, Runtime, Context, Socket, Msg, Poll, Proxy, Security, Helper — umbrella ZeroMQ.inc.

x86 Runtime

Bundled under Library\x86. Type features need ThinBASIC 1.4.0+.

Samples

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…

Type Wrapper Renames

ThinBASIC reserved words cannot be Type method names

Procedural Type method
ZmqBindSockBind
ZmqSend / ZmqRecvSockSend / SockRecv
ZmqErrnoGetErrno
ZmqPollDoPoll

PUB / SUB Example (Type wrapper)

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

Publisher (excerpt) ThinBASIC · x86
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
Subscriber (excerpt) $ZMQ_SUBSCRIBE before SockConnect
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))

Get Started

Environment · library · SDK build

Environment

  • Windows 10+
  • ThinBASIC 1.14+ (recommend)
  • 32-bit (x86) only
  • Type features: ThinBASIC 1.4.0+

Library

ThinBasicZMQ\Library\x86\
  libzmq.dll
  libsodium.dll

Native examples: interpreter + Library\x86 only.

SDK Build

cd SDK\C
build_pelles.bat

Copy thinBasic_ZeroMQ.dll to C:\thinBasic\Lib\

Message from ThinBASIC

Clone the repo, use x86 libzmq, and start with native includes or the SDK module.