Skip to content

Instantly share code, notes, and snippets.

@uorat
Last active September 19, 2016 10:39
Show Gist options
  • Save uorat/956e15664aa20ec5476c3dc17a463680 to your computer and use it in GitHub Desktop.
Save uorat/956e15664aa20ec5476c3dc17a463680 to your computer and use it in GitHub Desktop.
Sample server code for Socket.IO
// 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