mosquitto-client 获得拒绝连接

新手上路,请多包涵

我想通过 mosquitto 库使用 MQTT 协议。

首先,我想做一些安装 mosquitto-clients 的测试

 sudo apt-get install mosquitto-clients

该程序提供了两种“方法”:

  • mosquitto_pub
  • mosquitto_sub

按照 说明,我正在尝试提交新主题:

 mosquitto_sub -d -t newtopic/test

使用默认主机/端口 [localhost/1883]。

我得到:

 Error: Connection refused

错误太笼统了..有人可以帮助我吗?

可能是防火墙问题?在这种情况下,我如何检查这是否是问题所在?

我正在使用 linux ubuntu ( 3.8.0-42-generic #62~precise1-Ubuntu)

nb 使用 libmosquitto 编写自定义程序的相同行为。

原文由 Luca Davanzo 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.4k
2 个回答

mosquitto_pub/sub 的默认主机:端口组合是 localhost:1883。如果您的本地计算机上没有运行代理,那么它当然无法连接。

解决方案是在本地计算机上运行代理,或者告诉实用程序连接的位置。例如:

 mosquitto_sub -t newtopic/test -h test.mosquitto.org

原文由 ralight 发布,翻译遵循 CC BY-SA 3.0 许可协议

只需编辑 Mosquitto 配置文件 ( /etc/mosquitto/conf.d/mosquitto.conf ) 添加这些行…

allow_anonymous true

listener 1883 0.0.0.0

…并重新启动 Mosquitto(作为服务与否)。

$ sudo service mosquitto restart

或者

$ mosquitto --verbose --config-file /etc/mosquitto/conf.d/mosquitto.conf

如此 所述,自 v.1.7 起 allow_anonymous 默认为 false。检查日志消息( /var/log/mosquitto/mosquitto.log )也很有用。

Finally, run Mosquitto subscriber/publisher using --host ( -h ) parameter and the host IP address (get if from ifconfig or ip -color addr command )。

原文由 T77 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题