tlsSocket如何触发服务器的newSession和resumeSession事件
我有个tls的服务器,代码如下
'use strict'
var tls = require('tls');
var fs = require('fs');
var options = {
//options
}
var clients = [];
var server = tls.createServer(options);
server.on('secureConnection', function (tlsSocket) {
console.log('new connection,authorized:', tlsSocket.authorized);
tlsSocket.write('welcome,there is ' + clients.length + ' guests.\n');
});
const tlsSessionStore = {};
server.on('newSession', (id, data, cb) => {
console.log('newSession');
tlsSessionStore[id.toString('hex')] = data;
cb();
});
server.on('resumeSession', (id, cb) => {
console.log('resumeSession');
cb(null, tlsSessionStore[id.toString('hex')] || null);
});
server.listen(6666, function () {
console.log('TLS listened on port 6666');
});
客户端的代码是:
'use strict'
var tls = require('tls');
var fs = require('fs');
//使用客户端私钥和证书创建服务器
var options = {
//options
}
};
process.stdin.resume();
var tlsSocket = tls.connect(options, function () {
console.log('连接成功');
process.stdin.pipe(tlsSocket, { end: false });
tlsSocket.pipe(process.stdout);
});
//接收服务器数据
tlsSocket.on('data', function (data) {
console.log('收到服务器数据:%s', data);
});
每次客户端连接服务器,newSession和resumeSession的事件都不会被触发,但是用openssl s_client -reconnect -port 6666 2>&1 -no_ticket 来测试,就能触发服务器的newSession和resumeSession事件(不加-no_ticket参数也不会触发),我想能尽量复用连接会话提高连接效率,请问该怎么做才能复用会话呢?