简体   繁体   English

WebSocket握手错误网:: ERR_CONNECTION_RESET

[英]WebSocket handshake error net::ERR_CONNECTION_RESET

I'm trying to connect Paho JS lib to Snap! 我正在尝试将Paho JS lib连接到Snap! to allow communication with server through MQTT protocol, but somehow WebSockets keep crashing on me. 允许通过MQTT协议与服务器进行通信,但是WebSocket总是以某种方式崩溃。

Here's the code i use: 这是我使用的代码:

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 is implemented before (used mqttws31.js but the same results). mqttws31.min.js之前已实现(使用了mqttws31.js,但结果相同)。

I have mosquitto 1.4.8 installed with following config: 我使用以下配置安装了mosquitto 1.4.8:

    # 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

The JS code runs from html file on pythons SimpleHTTPServer and after running always prints this in console: JS代码从python SimpleHTTPServer上的html文件运行,运行后始终在控制台中打印:

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

with this as error code on onFail function: 以此作为onFail函数上的错误代码:

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

On the server side (mosquitto) i get following log: 在服务器端(mosquitto),我得到以下日志:

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.

So i guess it must be fault somewhere in the code part, but i'm totally lost here. 所以我想这一定是代码部分中的错误,但是我在这里完全迷路了。

The protocol definition should be on a separate line to the listener in the configuration file. protocol定义应位于配置文件中listener的单独行中。 At the moment they are being ignored so both listeners are being interpreted as native MQTT. 目前,它们已被忽略,因此两个侦听器都被解释为本地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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复 websocket 错误:WebSocket 握手期间出错:net::ERR_CONNECTION_RESET - How to fix websocket error: Error during WebSocket handshake: net::ERR_CONNECTION_RESET Javascript 套接字(失败:WebSocket 握手期间出错:net::ERR_CONNECTION_RESET) - Javascript Sockets (failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET) Django 通道失败:WebSocket 握手期间出错:net::ERR_CONNECTION_RESET - Django Channels failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET 如何修复错误POST ... net :: ERR_CONNECTION_RESET - How fix error POST … net::ERR_CONNECTION_RESET Http请求-&gt; net_error = -101(ERR_CONNECTION_RESET) - Http request --> net_error = -101 (ERR_CONNECTION_RESET) 随机net :: ERR_CONNECTION_RESET问题 - Random net::ERR_CONNECTION_RESET issues net :: ERR_CONNECTION_RESET与Tomcat 6 - net::ERR_CONNECTION_RESET with Tomcat 6 jQuery:.net::ERR_CONNECTION_RESET - jQuery: net::ERR_CONNECTION_RESET 从Node JS服务器网络上上传视频时出错:: ERR_CONNECTION_RESET - Error on uploading on video from Node JS server net::ERR_CONNECTION_RESET JavaScript获取请求错误:无法加载资源:net :: ERR_CONNECTION_RESET - JavaScript get request error: Failed to load resource: net::ERR_CONNECTION_RESET
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM