Launch the daemon, connect a simulator, send a message, and watch it travel through NSB โ all in under 10 minutes.
Prerequisite: Completed Get Started โ NSB installed and verified. Complete that guide first if you haven't already.
A complete message round-trip through NSB โ from your application, through the daemon, through a mock simulator, and back.
Save the following as config.yaml in your working directory.
---
system:
daemon_address: 127.0.0.1 # address where the NSB daemon runs
daemon_port: 65432 # port the daemon listens on
mode: 0 # 0 = PULL (clients request messages)
simulator_mode: 1 # 1 = Per-Node (each node has its own SimClient)
database:
use_db: false # false = direct transmission, no Redis neededuse_db: false transmits payloads directly through NSB without storage. Redis can be enabled later for large-payload scenarios. Database Settings โOpen Terminal 1 and launch the daemon with your config file.
./build/nsb_daemon config.yaml/[your/install/path]/nsb/bin/nsb_daemon config.yamlOpen Terminal 2. This pre-built simulator fetches payloads from NSB and passes them straight through โ no real network simulator needed.
import nsb_client as nsb
# Connect to NSB as a simulator client
sim = nsb.NSBSimClient("node0", "127.0.0.1", 65432)
# Fetch the payload waiting to be simulated
entry = sim.fetch()
if entry:
src = entry.source
dst = entry.destination
payload = entry.payload
print(f"Simulating: {src} -> {dst}, payload: {payload}")
# For this quickstart, pass straight through.
# In a real simulator, you would route via ns-3 or OMNeT++ here.
sim.post(src, dst, payload)
print("Posted payload as delivered")python3 simulator.pyfetch() when messages arrive.Open Terminal 3. This sends a payload and waits to receive it back.
import nsb_client as nsb
import time
# Connect to NSB as an application client
app = nsb.NSBAppClient("node0", "127.0.0.1", 65432)
# Send a payload to "node1"
app.send("node1", b"Hello from node0!")
print("Sent payload")
# Poll for a response
time.sleep(1)
entry = app.receive()
if entry:
print(f"Received: {entry.payload} from {entry.source}")
else:
print("No message received")python3 app.py./build/nsb_daemon config.yamlpython3 simulator.pypython3 app.pyCheck these outputs match before continuing.
Simulating: node0 -> node1, payload: b'Hello from node0!'
Posted payload as deliveredSent payload
Received: b'Hello from node0!' from node0A complete round-trip where node0 sends to node1, and node1 replies back. This shows the full Per-Node simulator mode in action.
import nsb_client as nsb
import time
app = nsb.NSBAppClient("node0", "127.0.0.1", 65432)
app.send("node1", b"Hello, node1!")
print("[node0] Sent message")
time.sleep(2)
entry = app.receive()
if entry:
print(f"[node0] Received reply: {entry.payload}")import nsb_client as nsb
import time
app = nsb.NSBAppClient("node1", "127.0.0.1", 65432)
time.sleep(1)
entry = app.receive()
if entry:
print(f"[node1] Received: {entry.payload}")
app.send(entry.source, b"Hello back, node0!")import nsb_client as nsb
import time
sim0 = nsb.NSBSimClient("node0", "127.0.0.1", 65432)
sim1 = nsb.NSBSimClient("node1", "127.0.0.1", 65432)
for _ in range(2):
for sim in [sim0, sim1]:
entry = sim.fetch(timeout=0) # non-blocking poll
if entry:
print(f"[sim] Routing {entry.source} -> {entry.destination}")
time.sleep(0.1) # simulate 100ms network delay
sim.post(entry.source, entry.destination, entry.payload)
time.sleep(3)Explore the full NSB documentation and tutorials.
Get assistance and find answers to common questions.