Last active
September 19, 2016 10:39
-
-
Save uorat/956e15664aa20ec5476c3dc17a463680 to your computer and use it in GitHub Desktop.
Sample server code for Socket.IO
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
// sockcet.io sample code | |
var socketIO = require('socket.io'); | |
var io = socketIO.listen(3000); | |
// event that clietns connect | |
io.sockets.on('connection', function(socket) { | |
console.log("connection"); | |
// event when recieving messages | |
socket.on('message', function(data) { | |
console.log("message"); | |
io.sockets.emit('message', data); | |
}); | |
// event that clients disconnect | |
socket.on('disconnect', function(){ | |
console.log("disconnect"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment