我有一个用Chrome打开的test.html
文件:
<html>
<head>
<script src="https://unpkg.com/mqtt/dist/mqtt.min.js"></script>
</head>
<body>
<script>
var client = mqtt.connect('ws://broker.hivemq.com:8000')
client.subscribe("mqtt/demo")
client.on("message", function (topic, payload) {
alert([topic, payload].join(": "))
client.end()
})
client.publish("mqtt/demo", "hello world!")
</script>
</body>
</html>
不幸的是我遇到这个错误:
mqtt.min.js:1 WebSocket connection to 'ws://broker.hivemq.com:8000/' failed: Connection closed before receiving a handshake response
我也尝试使用mqtt://
,但它不起作用。任何想法?
答案 0 :(得分:1)
此服务器已停止或关闭,无法访问。请使用
ws://broker.emqx.io:8083/mqtt
或
ws://broker.mqttdashboard.com:8000/mqtt
尝试