2017-05-31 4 views
0

私はPaho JSのlibをSnapに接続しようとしています! MQTTプロトコルを介してサーバーと通信することができますが、何とかWebSocketsがクラッシュし続けます。WebSocketハンドシェイクエラーnet :: ERR_CONNECTION_RESET

ここで私が使用するコードです:

var wsbroker = "127.0.0.1"; 
var wsport = 9001; 

console.log("Connecting to: ", wsbroker); 
console.log("Connecting to port: ", Number(wsport)); 

client = new Paho.MQTT.Client(wsbroker, Number(wsport),"Snap"); 

// set callback handlers 
client.onConnectionLost = onConnectionLost; 
client.onMessageArrived = onMessageArrived; 

// connect the client 
var client_options = { 
    onSuccess:onConnect, 
    onFailure:doFail 
} 

client.connect(client_options); 

// called when the client connects 
function onConnect() { 
    // Once a connection has been made, make a subscription and send a message. 
    console.log("Client connected..."); 
    client.subscribe("/Navicula/test"); 
    message = new Paho.MQTT.Message("CONNECTED"); 
    message.destinationName = "/Navicula/test"; 
    client.send(message); 
} 

function doFail(e){ 
    console.log("I haz failed"); 
    console.log(e); 
} 

// 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); 
} 

mqttws31.min.jsを前に(使用mqttws31.jsが、同じ結果を)実装されています。

私は、以下の設定でインストールmosquitto 1.4.8を持っている:

JSコードはニシキヘビSimpleHTTPServer上で、常に実行した後に、HTMLファイルから実行
# Place your local configuration in /etc/mosquitto/conf.d/ 
    # 
    # A full description of the configuration file is at 
    # /usr/share/doc/mosquitto/examples/mosquitto.conf.example 

    pid_file /var/run/mosquitto.pid 

    listener 1883 127.0.0.1 protocol mqtt 
    listener 9001 127.0.0.1 protocol websockets 

    persistence true 
    persistence_location /var/lib/mosquitto/ 

    log_dest file /var/log/mosquitto/mosquitto.log 

    include_dir /etc/mosquitto/conf.d 

は、コンソールでこの出力します。これで

WebSocket connection to 'ws://127.0.0.1:9001/mqtt' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET 

onFail関数のエラーコード:

Object {invocationContext: undefined, errorCode: 7, errorMessage: "AMQJS0007E Socket error:undefined."} 

サーバー側(モスキー私は次のログを取得します:

1496269205: mosquitto version 1.4.8 (build date Fri, 19 Feb 2016 12:03:16 +0100) starting 
1496269205: Config loaded from myconf.conf. 
1496269205: Opening ipv4 listen socket on port 1883. 
1496269205: Opening ipv4 listen socket on port 9001. 
1496269215: New connection from 127.0.0.1 on port 9001. 
1496269215: Socket error on client <unknown>, disconnecting. 
1496269215: New connection from 127.0.0.1 on port 9001. 
1496269215: Socket error on client <unknown>, disconnecting. 
1496269224: New connection from 127.0.0.1 on port 9001. 
1496269224: Socket error on client <unknown>, disconnecting. 
1496269224: New connection from 127.0.0.1 on port 9001. 
1496269224: Socket error on client <unknown>, disconnecting. 

私はそれがコード部分のどこかに欠陥があるはずですが、私はここで完全に失われていると思います。

答えて

0

の定義は、設定ファイルのlistenerとは別の行に記述する必要があります。現時点では無視されているため、両方のリスナーがネイティブMQTTとして解釈されています。

pid_file /var/run/mosquitto.pid 

listener 1883 127.0.0.1 
protocol mqtt 

listener 9001 127.0.0.1 
protocol websockets 

persistence true 
persistence_location /var/lib/mosquitto/ 

log_dest file /var/log/mosquitto/mosquitto.log 

include_dir /etc/mosquitto/conf.d 
+0

私は同じエラーがあります。私の設定リスナとプロトコルは、127.0.0.1を除いて記述したものと同じです。他に何が間違っている可能性がありますか?私は、他のモスキートインスタンスを使用しているときにのみ、メッセージを公開して購読することができます。 – TheUnreal

+0

@Unrealはすべて新しい質問(これを必要とするものを参照)を含み、独自のログと設定ファイルを含みます。 – hardillb

関連する問題