我一直在尝试开发一个C代码,使用蚊子库在TLS上发布关于蚊子经纪人的消息。我在蚊子侧配置了TLS,它工作得很好。我能够使用mosquitto_pub和mosquitto_sub发送和接收消息。
但是,当我尝试使用我的C代码发布消息时,它不起作用。显然,代码连接良好并发送消息,没有错误,但订阅者没有读取任何内容。
下面是我使用的publisher代码:
ReportSender::ReportSender()
{
mosquitto_lib_init();
mosquitoStruct = mosquitto_new (NULL, true, NULL);
mosquitto_tls_opts_set(mosquitoStruct, 1, NULL, NULL);
mosquitto_tls_set(mosquitoStruct, "~/temp/keys/secondAttempt/server.crt", NULL, NULL, NULL, NULL);
mosquitto_tls_insecure_set(mosquitoStruct, false);
mosquitto_connect_callback_set(mosquitoStruct, connect_cb);
mosquitto_publish_callback_set(mosquitoStruct, publish_cb);
mosquitto_log_callback_set(mosquitoStruct, log_cb);
mosquitto_connect (mosquitoStruct, MQTT_BROKER, MQTT_PORT, 0);
const char *reportRef = "Hello Word!";
// Publish the message to the topic
mosquitto_publish (mosquitoStruct, NULL, MQTT_TOPIC,
strlen(reportRef), reportRef, 0, false);
sleep (20);
}订阅者是:
mosquitto_sub -h 192.168.56.101 -p 8883 -t "#" -v --cafile server.crt怎么啦?
谢谢,毛罗
发布于 2018-04-30 17:45:40
您应该查看loop*()函数集,这些函数是处理后台网络流量所必需的。publish()不是阻塞调用。
https://stackoverflow.com/questions/50091875
复制相似问题