ThinBASIC · nanomsg · NNG · x86

ThinBasicNanoMsg

Nanomsg & NNG Wrapper for ThinBASIC

nanomsg NNG ThinBASIC 1.14+ x86 only Native + SDK Type wrapper MIT License

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

Two Ways to Call nanomsg / NNG

Do not mix #INCLUDE Core files with USES "NanoMsg" or USES "NNG"

Native

Core\NanoMsg.inc / Nng.inc · full procedural + Type wrapper

  • Full coverage
  • DLL via LibPath.inc (CWD → Library\x86)
  • No build — includes only
  • Constants: $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"

SDK Module

USES "NanoMsg" / USES "NNG" · thinBasic_*.dll

  • Core subset + LibraryInit
  • Path via NnLibraryInit(path) / NngLibraryInit(path)
  • Build: SDK\C\build_pelles.bat
  • Constants: %NN_* / %NNG_*
NanoMsg SDK/C → · NNG SDK/C →

Key Features

Messaging Patterns

PUB/SUB, REQ/REP, PUSH/PULL, Surveyor/Respondent, PAIR, BUS — both nanomsg and NNG packages.

Procedural + Type

LibNanomsgSocket, LibNngSocket, … with renamed methods where ThinBASIC reserved words conflict.

Dual Stack

Legacy nanomsg (SP) + modern NNG side-by-side. APIs are intentionally incompatible — pick one per project.

SDK Modules

thinBasic_NanoMsg.dll & thinBasic_NNG.dll — install to C:\thinBasic\Lib\.

Structured Core

Enums, Runtime, Socket, Msg, Poll, Helper — umbrella NanoMsg.inc / Nng.inc.

x86 Runtime

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

Samples

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\*

Type Wrapper Renames

ThinBASIC reserved words cannot be Type method names

Procedural Type method
NnBind / NngListenSockBind / Listen
NnSend / NnRecvSockSend / SockRecv
NnErrnoGetErrno
NnPollDoPoll

PUB / SUB Example (Type wrapper · NanoMsg)

Subscribe after Connect · start Pub first · port 1700

Publisher (excerpt) ThinBASIC · x86 · NanoMsg
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
Subscriber (excerpt) $NN_SUB_SUBSCRIBE after SockConnect
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

Get Started

Environment · library · SDK build

Environment

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

Library

ThinBasicNanoMsg\Library\x86\
  nanomsg.dll
ThinBasicNNG\Library\x86\
  nng.dll

Native examples: interpreter + Library\x86 only.

SDK Build

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\

Message from ThinBASIC

Clone the repo, use x86 nanomsg/nng, and start with native includes or the SDK modules.