Skip to content

Instantly share code, notes, and snippets.

@luizbafilho
Last active August 29, 2015 14:11
Show Gist options
  • Save luizbafilho/5d9e2085353a01aadd80 to your computer and use it in GitHub Desktop.
Save luizbafilho/5d9e2085353a01aadd80 to your computer and use it in GitHub Desktop.
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.get('/', function(req, res){
res.send('<h1>Hello world</h1>');
});
io.on('connection', function(socket){
console.log('a user connected');
socket.on('change', function(msg){
console.log('patch: ', msg);
socket.broadcast.emit('change', msg)
});
socket.on('disconnect', function () {
io.sockets.emit('user disconnected');
});
});
http.listen(3000, function(){
console.log('listening on *:3000');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment