我在 Linux 下使用 mosquitto 的 cpp 包装器。
初始化后:
this->keepalive = 60;
this->id = id;
this->port = port;
this->host = host;
this->topic = topic;
mosquittopp::log_init(MOSQ_LOG_ALL, MOSQ_LOG_STDOUT);
const int result = connect(host, port, keepalive);
如何发布我的自定义消息?
我正在使用包装器定义的发布方法,如下所示:
int publish(uint16_t *mid, const char *topic, uint32_t payloadlen=0, const uint8_t *payload=NULL, int qos=0, bool retain=false);
所以我可以这样调用:
publish(NULL, topic, strlen(message));
但是..我可以在哪里指定真正的“消息”?
最佳答案
在这里您可以使用 C++ 编写发布示例的示例代码 http://www.disk91.com/2013/technology/programming/mosquitto-c-sample-code-to-publish-message/
关于c++ - 蚊子 : publish message to broker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24534711/