【发布时间】:2018-08-31 22:11:34
【问题描述】:
我正在使用 paho js 客户端连接到 mosquitto。它连接正常。但是 onConnect 事件正在不停地触发。我正在检查代理中的日志,看起来它只连接了一次。为什么会这样?我只是使用了官网上出现的代码:
<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>
【问题讨论】:
-
你有多少用户?
-
只有一个。我正在 mosquitto 上测试 websocket 连接
-
我在 github 上播种,其他人对蚊子 1.5 有同样的问题。但我没有找到任何解决方案
-
快速浏览一些问题意味着这可能会在 Mosquitto 1.5.1 中得到修复,如果不降级到 1.4.15 可能是前进的方向。
标签: javascript client mqtt paho