【发布时间】:2016-12-09 12:00:03
【问题描述】:
通过包含 mqttws32.js 文件,使用 MQTT 和 mosquitto 代理实现 websocket。
Mosquitto 版本:1.4.9
一开始我得到了:
rohan@rohan-PC:~$ mosquitto
1470241326: mosquitto version 1.4.9 (build date Fri, 03 Jun 2016 09:22:47 +0100) starting
1470241326: Using default config.
1470241326: Opening ipv4 listen socket on port 1883.
1470241326: Opening ipv6 listen socket on port 1883.
由于 mosquitto 最新版本支持 Web 套接字。
我正在使用以下代码:
client = new Paho.MQTT.Client("localhost", 1883, "myclientid_" + parseInt(Math.random() * 100, 10));
得到错误:
到 'ws://localhost:1883/mqtt' 的 WebSocket 连接失败:错误 连接建立:net::ERR_CONNECTION_REFUSED
我得到了听众:
1470241581: New connection from ::1 on port 1883.
1470241581: Socket error on client <unknown>, disconnecting.
经过搜索,我找到了一个解决方案,可以在 mosquitto.conf 文件中添加以下行
listener 1884
protocol websockets
我将端口更改为 1884,但仍然遇到同样的错误。
【问题讨论】:
-
你用的是什么版本的 mosquitto?另外请在启动时使用 mosquitto 输出更新问题,以便我们可以看到侦听器已正确设置
-
rohan@rohan-PC:~$ mosquitto 1470241326:mosquitto 版本 1.4.9(构建日期,星期五,2016 年 6 月 3 日 09:22:47 +0100)从 1470241326 开始:使用默认配置。 1470241326:在端口 1883 上打开 ipv4 监听套接字。 1470241326:在端口 1883 上打开 ipv6 监听套接字。
-
编辑问题,不要尝试将输出作为 cmets 发布
-
完成.. 在启动时添加输出,并在与 web 套接字连接后添加输出
标签: javascript websocket mqtt mosquitto