![](/img/trans.png)
[英]Can I use native mqtt to connect to my mqtt broker without the use of websockets?
[英]How to connect to a MQTT Broker with Websockets?
我有一個用 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 連接到“ws://broker.hivemq.com:8000/”失敗:在收到握手響應之前連接已關閉
我也試過mqtt://
並且它不起作用。 任何的想法?
此服務器已停止或關閉,無法訪問。 請用
ws://broker.emqx.io:8083/mqtt
或者
ws://broker.mqttdashboard.com:8000/mqtt
嘗試
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.