0

エラーが発生しています

SCRIPT12152: WebSocket エラー: ネットワーク エラー 12152、サーバーが無効または認識できない応答を返しました

IE で、および

'ws://192.168.1.100:1883/' への WebSocket 接続に失敗しました: ハンドシェイク応答を受信する前に接続が閉じられました

クロムで..以下は私が使用したコードです

<!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>
4

1 に答える 1

2

mosquitto が提供する Windows 用のバイナリを使用している場合は、libwebsockets サポートが有効になっていないことに注意してください。Windows で mosquitto を使用して websocket をサポートする必要がある場合は、libwebsockets を自分でコンパイルし、websockets のサポートを有効にしてから mosquitto をコンパイルする必要があります。

現在、Windows での libwebsockets のサポートはそれほど大きくないことにも注意してください。特に、接続されているクライアントの数は 64 に制限されています。

于 2015-07-02T15:30:28.997 に答える