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 mock simulator fetches payloads from NSB and passes them straight through โ no real network simulator needed.
import nsb_client as nsb
import time
# Connect to NSB as a simulator client
sim = nsb.NSBSimClient("node0", "127.0.0.1", 65432)
print("Mock simulator ready โ waiting for messages...", flush=True)
while True:
entry = sim.fetch(timeout=1)
if entry:
src = entry.src_id
dst = entry.dest_id
payload = entry.payload
print(f"Simulating: {src} -> {dst}, payload: {payload}", flush=True)
# 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", flush=True)
break
time.sleep(0.1)fetch(timeout=1) checks for a message and returns immediately if none is available yet โ it does not mean the simulator gives up after one second. The surrounding loop keeps checking until a message arrives, so you can start the application whenever you are ready.python3 simulator.pyfetch() when messages arrive. Once the daemon and simulator are running, you can start the application whenever you are ready โ there is no need to launch it immediately.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 through the mock simulator
app.send("node0", b"Hello from node0!")
print("Sent payload")
# Poll for a response
print("Waiting for response...", flush=True)
while True:
entry = app.receive()
if entry:
print(f"Received: {entry.payload} from {entry.src_id}", flush=True)
break
time.sleep(0.1)python3 app.py./build/nsb_daemon config.yamlpython3 simulator.pypython3 app.pyCheck these outputs match before continuing.
Mock simulator ready โ waiting for messages...
Simulating: node0 -> node0, payload: b'Hello from node0!'
Posted payload as deliveredSent payload
Waiting for response...
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")
print("[node0] Waiting for reply...", flush=True)
while True:
entry = app.receive()
if entry:
print(f"[node0] Received reply: {entry.payload}", flush=True)
break
time.sleep(0.1)import nsb_client as nsb
import time
app = nsb.NSBAppClient("node1", "127.0.0.1", 65432)
print("[node1] Waiting for message...", flush=True)
while True:
entry = app.receive()
if entry:
print(f"[node1] Received: {entry.payload}", flush=True)
app.send(entry.src_id, b"Hello back, node0!")
print("[node1] Sent reply", flush=True)
break
time.sleep(0.1)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)
simulators = [sim0, sim1]
messages_processed = 0
print("[sim] Mock simulator ready โ waiting for messages...", flush=True)
while messages_processed < 2:
for sim in simulators:
entry = sim.fetch(timeout=0)
if entry:
print(f"[sim] Routing {entry.src_id} -> {entry.dest_id}")
time.sleep(0.1)
sim.post(entry.src_id, entry.dest_id, entry.payload)
messages_processed += 1
time.sleep(0.1)./build/nsb_daemon config.yamlpython3 simulator.pypython3 app_node1.pypython3 app_node0.pyINFO or WARNING log lines. The lines below are the important application-level output โ your terminals will not be limited to only these lines.[sim] Mock simulator ready โ waiting for messages...
[sim] Routing node0 -> node1
[sim] Routing node1 -> node0[node1] Waiting for message...
[node1] Received: b'Hello, node1!'
[node1] Sent reply[node0] Sent message
[node0] Waiting for reply...
[node0] Received reply: b'Hello back, node0!'Explore the full NSB documentation and tutorials.
Get assistance and find answers to common questions.