无法连接到Mosquitto经纪人

时间:2019-05-04 16:48:22

标签: mqtt

我正在尝试使用Paho库通过javascript与我的“ localhost” Mosquitto代理建立连接。 我似乎无法使其工作。 .conf文件可能需要进行一些调整。

尝试使用以下JavaScript连接到我的本地Mosquitto经纪人:

Future[Seq[Option[Event]]]

mosquitto.conf文件是典型的,并添加了以下几行:

<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.js" type="text/javascript"></script> 
<script> 
function btnclk(){
alert ("Will try to connect");
var client = new Paho.MQTT.Client("localhost",1883,"00001");

var options = {

     //connection attempt timeout in seconds
     timeout: 3,

     //Gets Called if the connection has successfully been established
     onSuccess: function () {
         alert("Connected");
     },

     //Gets Called if the connection could not be established
     onFailure: function (message) {
         alert("Connection failed: " + message.errorMessage);
     }
      };

//Attempt to connect
client.connect(options);


}
</script> 
</head>
<body>
<p>
<button type="button" onclick="btnclk()">Connect</button>
</p>


</body>
</html>

我得到的结果是:

与'ws:// localhost:1883 / mqtt'的WebSocket连接失败:WebSocket握手期间出错:net :: ERR_CONNECTION_RESET

当尝试通过端口1883和

连接到本地主机时

与'ws:// localhost:8080 / mqtt'的WebSocket连接失败:WebSocket握手期间出错:意外的响应代码:200

当尝试连接到端口8080时

任何帮助表示赞赏。

0 个答案:

没有答案
相关问题