【问题标题】:WebSocket opcode 7 with wss://带有 wss:// 的 WebSocket 操作码 7
【发布时间】:2013-06-03 12:00:42
【问题描述】:

上周二,我尝试在 wss:// 中启动服务器,但没有成功。今天我决定看一下WebSocket代码,我发现为什么我的WebSocket直接关闭了。这是我发现的错误代码:

1002 Unsupported usage of rsv bits without negotiated extension.
VALUE OF RSV1:Opcode: 7, fin: false, length: 69, hasPayload: true, masked: false

我的程序适用于 ws://,但不适用于 wss://。我不明白为什么 TLS 被阻止。

我精确的 IPtables 已停止并且我的证书正常。

你有什么想法吗?

如果你想看,下面是我的代码:

var fs = require('fs');
var https = require('https');
var WebSocketServer = require('websocket').server;
var express = require('express');

var serverTLS = express.createServer({
    key: fs.readFileSync(__dirname + '/notification_mail/notification.mail.com.key'),
    cert: fs.readFileSync(__dirname + '/notification_mail/notification.mail.com.crt')
});

serverTLS.configure(function(){
    serverTLS.set('views',__dirname);
    serverTLS.set('view engine','ejs');
});

serverTLS.get('/',function(req,res){
    res.render('index',{layout: false });
});

serverTLS.listen("443");

var wss = new WebSocketServer({ httpServer: serverTLS, autoAcceptConnections: true });

wss.on('connect', function(connection) {
    console.log((new Date()) + " Connection accepted.");

    connection.on('close', function(connection) {
            console.log((new Date()) + " Disconnected");
    });
});

console.log("Server launch");

还有我的 HTML 文件

<html>
<head>
 <meta charset="utf-8">
 <title>Example</title>
</head>
<body>
<h1>Serveur 2</h1>
<div id="tchat"></div>
<script>
   var url = "wss://notification.mail.com";
   var wsCtor = window['MozWebSocket'] ? MozWebSocket : WebSocket;
   this.socket = new wsCtor(url, 'connect');

   this.socket.onclose = function(){
      alert ("Connection lost");
   }
</script>
</body>
</html>

【问题讨论】:

    标签: javascript node.js https websocket


    【解决方案1】:

    错误信息令人困惑,因为

    您尝试过 Chrome 还是 IE10?

    您也可以尝试在您的节点服务器上运行AutobahnTestsuite

    测试套件具有支持 WSS 的 fuzzingclient 模式。测试套件包含大量的线路日志报告,可能有助于了解发生了什么。

    披露:我是 Autobahn 的原作者,为 Tavendo 工作。

    【讨论】:

      【解决方案2】:

      我启动了 wss://(但在 .NET 上),我也得到了 7 个操作码。我每 5 秒使用一次ReadTimeout (ReceiveTimeout) 向客户端发送“ping”。在 ws:// 和 wss:// 都运行良好,但在 wss:// 每 5 秒我得到“7 操作码”。

      我删除了超时并且它起作用了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-29
        • 2018-05-05
        • 1970-01-01
        • 2015-12-18
        • 2015-03-21
        • 2021-09-28
        相关资源
        最近更新 更多