Javascript paho js mqtt客户端触发onConnect事件

Javascript paho js mqtt客户端触发onConnect事件,javascript,client,mqtt,paho,Javascript,Client,Mqtt,Paho,我正在使用paho js客户端连接到MOSQUITO。没问题。但是onConnect事件正在不停地发射。我在检查broker中的日志,看起来它只连接了一次。为什么会这样?我刚刚使用了在官方网站上显示的代码: <html> <head> <title>JavaScript MQTT WebSocket Example</title> <script src="https://cdnjs.cloudflare.co

我正在使用paho js客户端连接到MOSQUITO。没问题。但是onConnect事件正在不停地发射。我在检查broker中的日志,看起来它只连接了一次。为什么会这样?我刚刚使用了在官方网站上显示的代码:

 <html>
   <head>
      <title>JavaScript MQTT WebSocket Example</title>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/paho- mqtt/1.0.1/mqttws31.js" type="text/javascript">
     </script>
     <script type = "text/javascript" language = "javascript">
           var host = "192.168.1.200";
        var port = 1884;
        // Create a client instance
         client = new Paho.MQTT.Client(host, port, "abcd");

     // set callback handlers
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;

// connect the client
client.connect({onSuccess:onConnect});


// called when the client connects
function onConnect() {
  // Once a connection has been made, make a subscription and send a message.
  console.log("onConnect");
  client.subscribe("World");
  message = new Paho.MQTT.Message("Hello");
  message.destinationName = "World";
  client.send(message);
    console.log("messageSent");
}

// called when the client loses its connection
function onConnectionLost(responseObject) {
  if (responseObject.errorCode !== 0) {
    console.log("onConnectionLost:"+responseObject.errorMessage);
  }
}

// called when a message arrives
function onMessageArrived(message) {
  console.log("onMessageArrived:"+message.payloadString);
}

      </script>
   </head>
     <body>
   <h1>Main Body</h1>
    <script>
    </script>
   </body>  
</html>

JavaScript MQTT WebSocket示例
var host=“192.168.1.200”;
var端口=1884;
//创建一个客户端实例
client=new Paho.MQTT.client(主机,端口,“abcd”);
//设置回调处理程序
client.onConnectionLost=onConnectionLost;
client.onMessageArrived=onMessageArrived;
//连接客户端
connect({onSuccess:onConnect});
//当客户端连接时调用
函数onConnect(){
//建立连接后,进行订阅并发送消息。
控制台日志(“onConnect”);
客户。认购(“世界”);
message=new Paho.MQTT.message(“Hello”);
message.destinationName=“世界”;
客户端。发送(消息);
console.log(“messageSent”);
}
//当客户端失去连接时调用
函数onConnectionLost(响应对象){
if(responseObject.errorCode!==0){
日志(“onConnectionLost:+responseObject.errorMessage”);
}
}
//消息到达时调用
函数onMessageArrived(消息){
log(“onMessageArrived:+message.payloadString”);
}
主体

当我的客户端ID(此处为“abcd”)已连接时,我通常会注意到这一点。为了在多个设备上部署,我将此设置为UUID。

您有多少用户?只有一个。我正在github上的Mosquitoi sow上测试websocket连接,还有其他人在蚊子1.5上有同样的问题。但我没有找到任何itA的解决方案快速查看一些问题意味着这可能会在MOSQUITO 1.5.1中得到解决,如果不是降级到1.4.15可能是前进的方向。