首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mosquitto不发布任何消息

Mosquitto不发布任何消息
EN

Stack Overflow用户
提问于 2018-04-30 06:24:06
回答 1查看 833关注 0票数 0

我一直在尝试开发一个C代码,使用蚊子库在TLS上发布关于蚊子经纪人的消息。我在蚊子侧配置了TLS,它工作得很好。我能够使用mosquitto_pub和mosquitto_sub发送和接收消息。

但是,当我尝试使用我的C代码发布消息时,它不起作用。显然,代码连接良好并发送消息,没有错误,但订阅者没有读取任何内容。

下面是我使用的publisher代码:

代码语言:javascript
复制
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);
}

订阅者是:

代码语言:javascript
复制
mosquitto_sub -h 192.168.56.101 -p 8883 -t "#" -v --cafile server.crt

怎么啦?

谢谢,毛罗

EN

回答 1

Stack Overflow用户

发布于 2018-04-30 17:45:40

您应该查看loop*()函数集,这些函数是处理后台网络流量所必需的。publish()不是阻塞调用。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50091875

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档