我收到错误
SCRIPT12152:WebSocket 错误:网络错误 12152,服务器返回无效或无法识别的响应
在 IE 中,和
WebSocket 连接到“ws://192.168.1.100:1883/”失败:连接在收到握手响应之前关闭
在 chrome.. 下面是我用过的一段代码
<!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>