Skip to content

Instantly share code, notes, and snippets.

@nadeemelahi
Created September 11, 2013 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nadeemelahi/6530732 to your computer and use it in GitHub Desktop.
Save nadeemelahi/6530732 to your computer and use it in GitHub Desktop.
//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