Created
November 12, 2011 10:59
-
-
Save jafstar/1360385 to your computer and use it in GitHub Desktop.
Move Thing - Server
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 fs = require('fs'); | |
var app = require('http').createServer(function(req, response){ | |
fs.readFile(__dirname+'/hello.html', function(err, data){ | |
response.writeHead(200, {'Content-Type':'text/html'}); | |
response.write(data); | |
response.end(); | |
}); | |
}); | |
app.listen(80); | |
var io = require('/somewhere/node_modules/socket.io').listen(app); | |
io.sockets.on('connection', function(socket){ | |
socket.emit('news',{hello: 'world'}); | |
socket.on('newMsg', function (data) { | |
console.log(data); | |
socket.broadcast.emit('writeMsg',data); | |
socket.emit('writeMsg',data); | |
}); | |
socket.on('newDir', function (data) { | |
console.log(data); | |
socket.broadcast.emit('writeDir',data); | |
socket.emit('writeDir',data); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment