上周二我尝试在 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:// 但不适用于 ws://。我不明白为什么 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>
最佳答案
错误信息令人困惑,因为
- 操作码 7 确实是保留的(https://www.rfc-editor.org/rfc/rfc6455#section-5.2),但是
- 它还提到了同样保留的RSV1,但没有给出观察值
您尝试过 Chrome 还是 IE10?
您也可以尝试运行 AutobahnTestsuite针对您的 Node 服务器。
测试套件有一个支持 WSS 的模糊客户端模式。测试套件包括大量的线路日志报告,可能有助于找出发生了什么。
披露:我是 Autobahn 的原作者,为 Tavendo 工作。
关于javascript - 带有 wss ://的 WebSocket 操作码 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16979693/