Skip to content

Instantly share code, notes, and snippets.

@caok
Last active December 19, 2015 14:49
Show Gist options
  • Save caok/5972114 to your computer and use it in GitHub Desktop.
Save caok/5972114 to your computer and use it in GitHub Desktop.
Node.js, Socket.io And SSL
// Load libraries
var https = require('https');
var fs = require('fs');
var socketio = require('socket.io');
// The server options
var svrPort = 8888; // This is the port of service
var svrOptions = {
key: fs.readFileSync('certs/server.key'),
cert: fs.readFileSync('certs/server.crt'),
ca: fs.readFileSync( 'bundle.crt')
};
// Create a Basic server and response
var servidor = https.createServer( svrOptions , function( req , res ){
res.writeHead(200);
res.end('Hi! Code here...');
});
// Create the Socket.io Server over the HTTPS Server
io = socketio.listen( servidor );
// Now listen in the specified Port
servidor.listen( svrPort );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment