Skip to content

Instantly share code, notes, and snippets.

@yickson
Created July 15, 2018 07:36
Show Gist options
  • Save yickson/28fa0ad20cd2914c239dbe5c9196691c to your computer and use it in GitHub Desktop.
Save yickson/28fa0ad20cd2914c239dbe5c9196691c to your computer and use it in GitHub Desktop.
Conexión Socket.io con SSL (HTTPS)
var fs = require('fs');
var options = {
key: fs.readFileSync('/ruta/a/tu/key.pem'),
cert: fs.readFileSync('/ruta/a/tu//fullchain.pem')
};
var app = require('https').createServer(options);
var io = require('socket.io').listen(app);
var port = 3000;
app.listen(port, function () {
console.log('Servidor escuchando en el %d', port);
});
io.sockets.on('connection', function (socket) {
socket.on( 'new_message', function( data ) {
io.sockets.emit( 'new_message', {
user: data.user,
nombre: data.nombre,
mensaje: data.mensaje,
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment