var https=require (' https '), var ws=require (' ws '), var fs=require (' FS '), Var keypath=process.cwd () + '/server.key ';// I put the secret key file in the directory under Run command to test var certpath=process.cwd () + '/server.crt ';//console.log (KeyPath);//console.log (Certpath); var options = { Key:fs.readFileSync (keypath), Cert:fs.readFileSync (Certpath), passphrase: ' 1234 '// If the secret key file has a password, use this property to set the password}; var server=https.createserver (options, function (req, res) {//If the simple HTTPS connection will return this thing Res.writehead (403);//403 Res.end ("This is a WebSockets server!\n");}). Listen (25550); var wss = new ws. Server ({server:server}),//To throw the created HTTPS server into the WebSocket creation function, WS will use this server to create the WSS service//. If an HTTP service is thrown in, then the WS-Service Wss.on (' Connection ', function (wsconnect) { wsconnect.on (' message '), function ( Message) { console.log (message); });});
node. JS creates a WSS service