Nanomsg & NNG Wrapper for ThinBASIC
High-performance messaging for ThinBASIC. Use the legacy nanomsg stack or modern NNG (nanomsg-next-gen) —
full native #INCLUDE APIs or optional SDK modules. PUB/SUB, REQ/REP, PUSH/PULL, Survey, PAIR, BUS and more.
x86 only. ThinBASIC is a 32-bit process — load only Library\x86
nanomsg.dll / nng.dll.
Do not use x64 builds from FreeBasicNanoMsg / PureBasicNanoMsg.
You can still talk to x64 peers over tcp:// (wire protocol is architecture-independent).
Do not mix #INCLUDE Core files with USES "NanoMsg" or USES "NNG"
Core\NanoMsg.inc / Nng.inc · full procedural + Type wrapper
LibPath.inc (CWD → Library\x86)$NN_* / $NNG_*#INCLUDE Once ".\Core\NanoMsg.inc"
#INCLUDE Once ".\Core\NanomsgWrapper.inc"
' or for NNG:
#INCLUDE Once ".\Core\Nng.inc"
#INCLUDE Once ".\Core\NngWrapper.inc"
USES "NanoMsg" / USES "NNG" · thinBasic_*.dll
NnLibraryInit(path) / NngLibraryInit(path)SDK\C\build_pelles.bat%NN_* / %NNG_*PUB/SUB, REQ/REP, PUSH/PULL, Surveyor/Respondent, PAIR, BUS — both nanomsg and NNG packages.
LibNanomsgSocket, LibNngSocket, … with renamed methods where ThinBASIC reserved words conflict.
Legacy nanomsg (SP) + modern NNG side-by-side. APIs are intentionally incompatible — pick one per project.
thinBasic_NanoMsg.dll & thinBasic_NNG.dll — install to C:\thinBasic\Lib\.
Enums, Runtime, Socket, Msg, Poll, Helper — umbrella NanoMsg.inc / Nng.inc.
Bundled under each package Library\x86. Type features need ThinBASIC 1.4.0+.
Procedural · Module · SDK examples · default ports 1700–1703
| Pattern | NanoMsg | NNG |
|---|---|---|
| PUB / SUB | PubServer / SubClient · port 1700 | same under ThinBasicNNG |
| REQ / REP | RepServer / ReqClient · port 1700 | same |
| PUSH / PULL | PushServer / PullClient · port 1701 | same |
| Survey | SurveyorServer / RespondentClient · 1702 | same |
| PAIR (inproc) | PairInproc | same |
| BUS | BusServer / BusClient · port 1703 | same |
| Type wrapper | Example\Module\*.tbasic | ThinBasicNNG\Example\Module\* |
| SDK examples | SDK\C\examples\* | SDK\C\examples\* |
ThinBASIC reserved words cannot be Type method names
| Procedural | Type method |
|---|---|
NnBind / NngListen | SockBind / Listen |
NnSend / NnRecv | SockSend / SockRecv |
NnErrno | GetErrno |
NnPoll | DoPoll |
Subscribe after Connect · start Pub first · port 1700
Uses "CONSOLE"
#INCLUDE Once "..\..\Core\NanomsgWrapper.inc"
Dim NnRuntime As LibNanomsgRuntime
Dim NnSocketRec As LibNanomsgSocket
Global Socket As Long
Global lpszServerAddr As String
Global lpszSendMessage As String
Global Rc As Long
lpszServerAddr = "tcp://*:1700"
Socket = NnSocketRec.NewSocket($AF_SP, $NN_PUB)
Rc = NnSocketRec.SockBind(Socket, lpszServerAddr)
If Rc < 0 Then
Printl("Bind failed: " & NnRuntime.GetStrerror(NnRuntime.GetErrno()))
Else
While %TRUE
lpszSendMessage = "quotes#Bid:…,Ask:…"
NnSocketRec.SockSendStr(Socket, lpszSendMessage, 0)
Sleep 500
Wend
End If
Socket = NnSocketRec.NewSocket($AF_SP, $NN_SUB)
Rc = NnSocketRec.SockConnect(Socket, "tcp://localhost:1700")
If Rc >= 0 Then
NnSocketRec.SockSetsockoptStr(Socket, $NN_SUB, $NN_SUB_SUBSCRIBE, "quotes")
While %TRUE
NnSocketRec.SockRecv(Socket, VarPtr(lpszRecvBuffer), SizeOf(lpszRecvBuffer), 0)
Printl(lpszRecvBuffer)
Wend
End If
Environment · library · SDK build
ThinBasicNanoMsg\Library\x86\
nanomsg.dll
ThinBasicNNG\Library\x86\
nng.dll
Native examples: interpreter + Library\x86 only.
cd ThinBasicNanoMsg\SDK\C
build_pelles.bat
cd ThinBasicNNG\SDK\C
build_pelles.bat
Copy thinBasic_NanoMsg.dll / thinBasic_NNG.dll to C:\thinBasic\Lib\
Clone the repo, use x86 nanomsg/nng, and start with native includes or the SDK modules.