到MQTT經紀人我正在錯誤無法連接使用javascript客戶
在IESCRIPT12152: WebSocket Error: Network Error 12152, The server returned an invalid or unrecognized response
,和
在鉻WebSocket connection to 'ws://192.168.1.100:1883/' failed: Connection closed before receiving a handshake response
..下面是我已經使用
的代碼段<!DOCTYPE html>
<html lang="en">
<head></head>
<body>
<script src="../bower_components/jquery/dist/jquery.min.js"></script>
<script src="../js/mqttws31.js"></script>
<script src="../js/mqttws31-min.js"></script>
<script src="../js/reconnecting-websocket.js"></script>
<script src="../js/reconnecting-websocket.min.js"></script>
<script>
// Create a client instance
client = new Paho.MQTT.Client("192.168.1.100", 1883, "100");
var s = new ReconnectingWebSocket("ws://192.168.1.100:1883");
// set callback handlers
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
// connect the client
client.connect({onSuccess:onConnect});
// called when the client connects
function onConnect() {
alert("connected");
// Once a connection has been made, make a subscription and send
console.log("onConnect");
client.subscribe("/World");
message = new Paho.MQTT.Message("Hello");
message.destinationName = "/World";
client.send(message);
}
// 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>
</body>
</html>
?它支持websockets嗎? – knolleary
我嘗試使用Mosquitto經紀人,然後我跑後面的問題,然後我換成HiveMQ經紀人,與我只是啓用websocket,並得到它固定 但事情是我讀蚊子1.4以上支持websocket我做了相同的變化,蚊子經紀人以及,但仍然是下降 –
您仍然連接到錯誤的端口。在另一個問題,我們爲蚊子設置的websocket端口是1884而不是1883 – hardillb