【发布时间】:2015-07-01 17:31:04
【问题描述】:
我收到了错误
SCRIPT12152:WebSocket 错误:网络错误 12152,服务器返回无效或无法识别的响应
在 IE 中,和
与“ws://192.168.1.100:1883/”的 WebSocket 连接失败:在收到握手响应之前连接已关闭
在 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>
【问题讨论】:
-
您使用的是什么代理?是支持 websockets 的吗?
-
我尝试使用 Mosquitto 代理然后我遇到了问题,然后我用 HiveMQ 代理替换了,我只是启用了 websocket 并修复了它但问题是我阅读了 mosquitto 1.4 以上支持我制作的 websocket蚊子经纪人也有同样的变化,但仍然下降
-
您仍然连接到错误的端口。在另一个问题中,我们为 mosquitto 设置的 websocket 端口是 1884 而不是 1883
-
使用 HiveMQ 代理,我确实将 websocket 的侦听器端口设置为 8000,现在它工作正常。抱歉没有添加此信息,我也删除了重新连接代码
-
请帮我处理 Mosquitto 经纪人
标签: windows websocket mqtt mosquitto hivemq