我已经创建了MQTT代理,并且已经配置了Web套接字。 这是我的配置文件。 (我不使用SSL)
#mqtt
listener 1883
protocol mqtt
#Websockets
listener 9001
protocol websockets
我正在运行我的MQTT代理(使用此命令$ mosquitto -c /path/to/mosquitto.conf
),这是日志文件。
1569230648: mosquitto version 1.4.15 (build date Tue, 18 Jun 2019 11:42:22 -0300) starting
1569230648: Config loaded from /etc/mosquitto/mosquitto.conf.
1569230648: Opening ipv4 listen socket on port 1883.
1569230648: Opening ipv6 listen socket on port 1883.
1569230648: Opening websockets listen socket on port 9001.
在我的网站上,我有此代码。
<!-- Script to import MQTT -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.js" type="text/javascript">
</script>
<!-- Script to connect to MQTT broker and retrieve current values -->
<script>
var websocket = "195.**.***.**";
var port = 9001;
client = new Paho.MQTT.Client(websocket, port, "web_connection" + parseInt(Math.random() * 100, 10));
// set callback handlers
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
var options = {
onSuccess: onConnect,
onFailure: doFail
}
// connect the client
client.connect(options);
.....
但是当我尝试连接我的网站时,Chrome出现此错误:
mqttws31.js:977 WebSocket connection to 'ws://195.**.***.**:9001/mqtt' failed: Error in connection establishment: net::ERR_CONNECTION_TIMED_OUT
我在路由器9001端口中打开。为什么客户端Web无法连接?
谢谢