NSBAppClient (C++)
Application-side client. Inherits from NSBClient.
Constructorโ
nsb::NSBAppClient nsb_conn(identifier, serverAddress, serverPort);
Parameters:
| Parameter | Type | Description |
|---|---|---|
identifier | const std::string& | Unique client identifier (e.g. "node0"). Must match NSBSimClient identifier in Per-Node mode. |
serverAddress | std::string& | IP address or hostname of the NSB Daemon. |
serverPort | int | Port number of the NSB Daemon. |
Construction behavior. Upon construction, the client connects to the daemon, sends INIT, receives system configuration, and optionally connects to Redis.
send(dest_id, payload)โ
Sends a payload to a destination via NSB.
std::string key = nsb_conn.send(dest_id, payload);
Parameters:
| Parameter | Type | Description |
|---|---|---|
dest_id | const std::string | Identifier of the destination application client. |
payload | std::string | The payload data to send. |
Returns: std::string โ Redis key for stored message (if database is configured), otherwise empty string.
Behavior: Fire-and-forget. Creates a SEND message and transmits to daemon. Daemon routes to simulator.
Example:
std::string payload = "Hello, World!";
nsb_conn.send("node1", payload);
receive()โ
Receives a payload via NSB.
// Default โ receive for self, with default timeout
MessageEntry entry = nsb_conn.receive();
// With explicit destination and timeout
MessageEntry entry = nsb_conn.receive(&dest_id, timeout);
// With timeout only
MessageEntry entry = nsb_conn.receive(timeout);
Signatures:
MessageEntry receive(std::string* destId, int timeout = DAEMON_RESPONSE_TIMEOUT);
MessageEntry receive(int timeout = DAEMON_RESPONSE_TIMEOUT);
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
destId | std::string* | nullptr | Pointer to destination identifier. Pass nullptr to receive for self. |
timeout | int | DAEMON_RESPONSE_TIMEOUT (30s) | Seconds to wait. Use 0 for non-blocking poll. |
Returns: MessageEntry โ Populated if message found; call exists() to check.
Behavior by mode:
- PULL mode: Sends RECEIVE request to daemon. Daemon responds with MESSAGE or NO_MESSAGE.
- PUSH mode: Waits on RECV channel using
selectwith given timeout. Usetimeout=0for polling.
Example:
MessageEntry entry = nsb_conn.receive();
if (entry.exists()) {
std::string payload = entry.payload_obj;
// process...
}
listenReceive()โ
Blocking listener โ for use in dedicated listener threads.
MessageEntry entry = nsb_conn.listenReceive();
Returns: MessageEntry
Purpose: Designed for a dedicated thread that blocks waiting for the next incoming payload, as an alternative to polling receive() in a loop.
Go Deeperโ
- MessageEntry โ the struct returned by
receive() - NSBSimClient โ the simulator-side counterpart, plus complete app/sim examples
- Python NSBAppClient โ the equivalent class in Python