Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jedireza/9b39e88079331ed0ff66ffaddaa800f6 to your computer and use it in GitHub Desktop.
Save jedireza/9b39e88079331ed0ff66ffaddaa800f6 to your computer and use it in GitHub Desktop.
'use strict';
const Fs = require('fs');
const Https = require('https');
const WebSocketServer = require('ws').Server;
const httpsServer = Https.createServer({
key: Fs.readFileSync(process.env.KEY),
cert: Fs.readFileSync(process.env.CERT)
});
const wss = new WebSocketServer({
server: httpsServer
});
httpsServer.on('request', (req, res) => {
res.writeHead(200);
res.end('hello HTTPS world\n');
});
wss.on('connection', (ws) => {
ws.send('hello');
ws.on('message', (data) => {
ws.send('message received: ', data);
});
ws.on('close', () => {
console.log('socket closed');
});
});
httpsServer.listen(443);
@cleardev0829
Copy link

Hi

@cleardev0829
Copy link

I have one question in your code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment