Last active
June 11, 2018 23:48
-
-
Save mkhizeryounas/2dfbfc00a30c3671a7b158017e95e8cf to your computer and use it in GitHub Desktop.
Socket io implementation in express generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/****** bin/www ******/ | |
// After -> server.listen(port); | |
// Addd the following for Socket.IO | |
var io = require('socket.io').listen(server); | |
require('../custom_modules/socket-helper')(io); | |
/****** socket-helper.js module ******/ | |
module.exports = function (io) { | |
io.on('connection', function(socket){ | |
console.log(socket.id); | |
socket.on('disconnect', function(){ | |
console.log('user disconnected'); | |
}); | |
socket.on('chat_message', function(msg){ | |
console.log( msg); | |
io.emit('chat_message',"-->" + msg); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment