在获胜10时使用websocket(Paho客户端)使用蚊子ERR_CONNECTION_REFUSED

时间:2019-09-05 18:03:46

标签: websocket mqtt mosquitto

我已经阅读了所有带有类似问题的主题,但找不到答案。

蚊子配置:

listener 1883 127.0.0.1
protocol mqtt
listener 9001 127.0.0.1
protocol websockets

日志输出:

1567705166: mosquitto version 1.6.2 starting
1567705166: Config loaded from C:\Program Files (x86)\mosquitto\mosquitto.conf.
1567705166: Opening ipv4 listen socket on port 1883.
1567705166: Opening websockets listen socket on port 9001.
1567705166: Opening websockets listen socket on port 1883.

Chrome开发者工具:

mqttws31.js:977 WebSocket connection to 'ws://127.0.0.1:9001/mqtt' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

我尝试了很多事情,但是没有帮助:

  1. 仅尝试使用websockets
  2. 尝试其他端口(1883和9001,而不是8080)
  3. 关闭Windows防火墙

如果我将配置文件更改为:

#listener 1884 127.0.0.1
#protocol mqtt
#listener 1883 127.0.0.1
protocol websockets

Mosquitto在端口1883上侦听websocket,但日志文件读取:

1567706943: mosquitto version 1.6.2 starting
1567706943: Config loaded from C:\Program Files (x86)\mosquitto\mosquitto.conf.
1567706943: Opening websockets listen socket on port 1883.
1567706943: Error in poll: No error.
1567706943: Error in poll: No error.
1567706943: Error in poll: No error.
1567706943: Error in poll: No error.
1567706943: Error in poll: No error.
1567706943: Error in poll: No error.
1567706943: Error in poll: No error.
1567706943: Error in poll: No error.
1567706943: Error in poll: No error.
1567706943: Error in poll: No error.

将配置更改为:

protocol websockets
listener 8080 127.0.0.1
protocol mqtt

给我一​​个日志文件,上面写着:

1567707450: mosquitto version 1.6.2 starting
1567707450: Config loaded from C:\Program Files (x86)\mosquitto\mosquitto.conf.
1567707450: Opening ipv4 listen socket on port 8080.
1567707450: Opening websockets listen socket on port 1883.

(没有多余的废话)

跟进答案1:

config:

protocol websockets
listener 1883 127.0.0.1
protocol mqtt

控制台:

WebSocket connection to 'ws://127.0.0.1:1883/mqtt' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET

日志:

1567716915: mosquitto version 1.6.2 starting
1567716915: Config loaded from C:\Program Files (x86)\mosquitto\mosquitto.conf.
1567716915: Opening ipv4 listen socket on port 1883.
1567716915: Opening websockets listen socket on port 1883.
1567716920: New connection from 127.0.0.1 on port 1883.
1567716920: Socket error on client <unknown>, disconnecting.
1567716920: New connection from 127.0.0.1 on port 1883.
1567716920: Socket error on client <unknown>, disconnecting.
5492: Error in poll: No error.
1567715492: Error in poll: No error.
1567715492: Error in poll: No error.
1567715492: Error in poll: No error.
1567715492: Error in poll: No error.
1567715492: Error in poll: No error.

尝试了另一个websockets客户端(https://www.eclipse.org/paho/clients/js/utility/)->连接失败:AMQJSC0001E连接超时。

我无法让Websocket与任何配置/端口一起使用... 谁能确认Win10的Mosquitto(32位版本1.6.2或1.6.4)中的Websocket是否正常工作?

2 个答案:

答案 0 :(得分:0)

您的第一个配置文件将无法工作,因为您都有本机MQTT和Websockets都试图在端口1883上侦听。(这是因为默认侦听器在端口1883上启动),除非100%确定,否则无法确定Windows上有一些奇怪的IPv6问题。

第二,只是将默认侦听器协议更改为Websockets,假设您尝试从网页连接到端口1883,则理论上应该可以使用。

第三个是在端口1883 Websockets上设置默认的侦听器,在8080上是本机的。假设您尝试连接到1883,同样可以正常工作

启用Websocket的最简单的配置应如下所示:

listener 9001 127.0.0.1
protocol websockets

这将在端口1883上保留本机默认侦听器(在所有接口上侦听,在bind_address 127.0.0.1行之前使用listener以使其仅在本地主机上侦听)并在端口9001上启动Websocket侦听器

答案 1 :(得分:0)

这真是个挑战。

首先,我尝试使用在线经纪人和客户来使事情正常进行。还是行不通。然后我切换到另一台计算机,一切正常。

切换回原始计算机后,我决定通过转到https://www.websocket.org/echo.html来测试websocket是否在正常工作 从那一刻起,一切开始起作用。首先是在线代理和客户端,然后是本地服务器和客户端。我不知道为什么...