Skip to main content

NSBAppClient (C++)

Application-side client. Inherits from NSBClient.

Constructorโ€‹

nsb::NSBAppClient nsb_conn(identifier, serverAddress, serverPort);

Parameters:

ParameterTypeDescription
identifierconst std::string&Unique client identifier (e.g. "node0"). Must match NSBSimClient identifier in Per-Node mode.
serverAddressstd::string&IP address or hostname of the NSB Daemon.
serverPortintPort 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:

ParameterTypeDescription
dest_idconst std::stringIdentifier of the destination application client.
payloadstd::stringThe 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:

ParameterTypeDefaultDescription
destIdstd::string*nullptrPointer to destination identifier. Pass nullptr to receive for self.
timeoutintDAEMON_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 select with given timeout. Use timeout=0 for 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โ€‹