eclipse paho 中的 MQTT 无法连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19741181/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 21:18:17  来源:igfitidea点击:

MQTT in paho can't connect in connection

eclipsemqttmosquittopaho

提问by user824624

I am trying to use the MQTT javascript client from Paho. I see a example from HiveMQ, you can check it here - - http://www.hivemq.com/demos/websocket-client/

我正在尝试使用 Paho 的 MQTT javascript 客户端。我看到一个来自 HiveMQ 的例子,你可以在这里查看 - - http://www.hivemq.com/demos/websocket-client/

It seems to be working, however when I set the host as: test.mosquitto.org:1883, which is a mqtt broker service at mosquitto, it fails.

它似乎正在工作,但是当我将主机设置为:时test.mosquitto.org:1883,它是 mosquitto 的 mqtt 代理服务,它失败了。

When I tried to connect to this mosquitto service, it gives me a error on connection - connect failed: AMQJS0007E, Socket error: undefined.

当我尝试连接到这个 mosquitto 服务时,它给了我一个连接错误 - connect failed: AMQJS0007E, Socket error: undefined.

回答by hardillb

Mosquitto does not support MQTT over WebSockets out of the box. So Roger is using lighttpd with the mod_websocket module to forward.

Mosquitto 不支持开箱即用的基于 WebSocket 的 MQTT。所以 Roger 使用了带有 mod_websocket 模块的 lighttpd 来转发。

This means that the port will be port 80 not 1883

这意味着端口将是端口 80 而不是 1883

But having just had a quick look at http://test.mosquitto.org/ws.htmlit seams that the lighttpd instance may be down at the moment as the demo is not working.

但是刚刚快速浏览了http://test.mosquitto.org/ws.html,可以看出 lighttpd 实例目前可能已关闭,因为演示无法正常工作。

If you want to run your own local copy of mosquitto for testing there is a link on that page with instructions on how to build mod_websocket for lighttpd or a ubuntu ppa to download it from.

如果您想运行自己的 mosquitto 本地副本进行测试,该页面上有一个链接,其中包含有关如何为 lighttpd 或 ubuntu ppa 构建 mod_websocket 的说明以从中下载它。

回答by ralight

As hardillb says, you need to use port 80. The full url you should use is

正如hardillb所说,您需要使用端口80。您应该使用的完整网址是

ws://test.mosquitto.org/mqtt

ws://test.mosquitto.org/mqtt

If you are using m2m.eclipse.org as Andy suggests (which is actually using apache with websockets support) then you should use

如果您按照安迪的建议使用 m2m.eclipse.org(实际上是使用具有 websockets 支持的 apache),那么您应该使用

ws://m2m.eclipse.org/ws

ws://m2m.eclipse.org/ws

回答by Andy Piper

You could try the same thing against m2m.eclipse.org which I think has websocket support switched on via lighthttpd as well.

你可以对 m2m.eclipse.org 尝试同样的事情,我认为它也通过 lighthttpd 开启了 websocket 支持。