bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
bitsim::distributed::MQTT_Transport Class Referencefinal

Participants in several processes, on one machine or several, that meet on an MQTT broker. More...

#include <mqtt_transport.h>

Inheritance diagram for bitsim::distributed::MQTT_Transport:
Collaboration diagram for bitsim::distributed::MQTT_Transport:

Public Member Functions

 MQTT_Transport (const std::string &broker, const std::string &world)
void publish (const std::string &bytes) override
 Send bytes to every other participant.
std::optional< std::string > receive (std::chrono::milliseconds timeout) override
 The next message from another participant, waiting at most timeout.
Public Member Functions inherited from bitsim::distributed::Transport
virtual ~Transport ()=default

Static Public Member Functions

static std::string topic (const std::string &world)

Detailed Description

Participants in several processes, on one machine or several, that meet on an MQTT broker.

Every participant of a world publishes to and subscribes to the topic "bitsim/world/<world>", so it also receives its own messages, which Synchroniser ignores. The messages are published with quality of service 0: a lost state is replaced by the next, or sent again by the synchroniser in lockstep. A robot on the network, a Raspberry Pi for example, joins the world by publishing StateMessage::encode() to the same topic.

Constructor & Destructor Documentation

◆ MQTT_Transport()

bitsim::distributed::MQTT_Transport::MQTT_Transport ( const std::string & broker,
const std::string & world )
Parameters
brokerthe address of the broker, "tcp://localhost:1883" for example
worldthe name of the world; participants of different worlds do not meet

Member Function Documentation

◆ publish()

void bitsim::distributed::MQTT_Transport::publish ( const std::string & bytes)
overridevirtual

Send bytes to every other participant.

Implements bitsim::distributed::Transport.

◆ receive()

std::optional< std::string > bitsim::distributed::MQTT_Transport::receive ( std::chrono::milliseconds timeout)
overridevirtual

The next message from another participant, waiting at most timeout.

Implements bitsim::distributed::Transport.

◆ topic()

std::string bitsim::distributed::MQTT_Transport::topic ( const std::string & world)
inlinestatic

The documentation for this class was generated from the following files: