上周二,我尝试在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>