Last active
August 29, 2015 14:11
-
-
Save luizbafilho/5d9e2085353a01aadd80 to your computer and use it in GitHub Desktop.
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
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