如何在Mosquitto中同时启用TCP和Web套接字?

rek*_*a s 4 sockets tcp mqtt mosquitto

我已经使用Paho库通过MQTT实现消息传递。在我的mosquitto.conf文件中,我具有以下内容:

listener 1883
protocol websockets
Run Code Online (Sandbox Code Playgroud)

此配置适用于Web应用程序。当我尝试使用带TCP的Android和iOS连接时,出现错误“连接超时”。当我禁用该protocol websockets行时,它可以在Android和iOS上使用,但是该网页无法连接。

当我尝试测试MQTT服务器test.mosquitto.org时,一切正常。

请告诉我,我需要它与Android,iOS和Web应用程序一起使用,同时支持WebSocket和TCP连接。

ral*_*ght 9

您需要定义两个侦听器,一个用于tcp上的mqtt,另一个用于websockets:

# this will listen for mqtt on tcp
listener 1883

# this will expect websockets connections
listener 8080
protocol websockets
Run Code Online (Sandbox Code Playgroud)

  • 当我尝试上述操作时,出现错误“连接失败:AMQJS0007E 套接字错误:未定义。重试” (2认同)