node搭建SSL加密的websocket服务器 wss

const WebSocket = require('ws');
 

var https = require('https');
var selfSigned = require('openssl-self-signed-certificate');

var options = {
    key: selfSigned.key,
    cert: selfSigned.cert
};

console.log(options);

const server = https.createServer(options,).listen(8089);
//console.log(`HTTPS started on port ${port + 1} (dev only).`);
const wss = new WebSocket.Server({ server });

wss.on('connection', function connection(ws) {
  ws.on('message', function incoming(message) {
    console.log('received: %s', message);
  });
 
  ws.send('something');
});

你可能感兴趣的:(node搭建SSL加密的websocket服务器 wss)