Created
September 11, 2013 22:37
-
-
Save nadeemelahi/6530732 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
//THIS WORKS FINE | |
var app = require('http').createServer(handler); | |
var io = require('socket.io').listen(app); | |
var static = require('node-static'); | |
// Make all the files in the current directory accessible | |
var fileServer = new static.Server('./public'); | |
app.listen(8000); | |
function handler(request, response) { | |
request.addListener('end', function () { | |
fileServer.serve(request, response); | |
}).resume(); | |
} | |
io.sockets.on('connection', function(socket){ | |
socket.send('Welcome client'); | |
socket.on('message', function(msg){ | |
console.log('client message: ' + msg); | |
}); | |
socket.on('disconnect', function(){ | |
console.log('client disconnected'); | |
}); | |
}); | |
//BUT THIS FAILS AND ALL I DID WAS MOVE .listen to the a new line? | |
var app = require('http').createServer(handler); | |
var io = require('socket.io'); | |
io.listen(app); | |
var static = require('node-static'); | |
// Make all the files in the current directory accessible | |
var fileServer = new static.Server('./public'); | |
app.listen(8000); | |
function handler(request, response) { | |
request.addListener('end', function () { | |
fileServer.serve(request, response); | |
}).resume(); | |
} | |
io.sockets.on('connection', function(socket){ | |
socket.send('Welcome client'); | |
socket.on('message', function(msg){ | |
console.log('client message: ' + msg); | |
}); | |
socket.on('disconnect', function(){ | |
console.log('client disconnected'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment