Socket.io: Client socket.io.js not found 404

Created on 30 Jun 2012  路  8Comments  路  Source: socketio/socket.io

Hi,
I'm trying to use socket.io(0.9.6) with express (3.00b4) and node (0.8.1). On a localhost.

When I create the base epxress server the socket.io client is not found.

I've tried uninstalling everything and reinstalling it.

This is my app.js code

var socket = require('socket.io')
var express = require('express')
  , routes = require('./routes')
  , http = require('http');


var app = express();

app.configure(function(){
  app.set('port', process.env.PORT || 3000);
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.favicon());
  app.use(express.logger('dev'));
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(express.cookieParser('your secret here'));
  app.use(express.session());
  app.use(app.router);
  app.use(require('less-middleware')({ src: __dirname + '/public' }));
  app.use(express.static(__dirname + '/public'));
});

app.configure('development', function(){
  app.use(express.errorHandler());
});

app.get('/', routes.index);

http.createServer(app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});


var server = http.createServer(app);

var io = socket.listen(server)

Most helpful comment

http.createServer(app).listen(app.get('port'), function(){})

That's your server. Not:

var server = http.createServer(app);

You're basically creating two http servers, the latter of which is not listening on any port. It's a zombie.

Turn your code into this:

var server = http.createServer(app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});

var io = socket.listen(server);
io.sockets.on('connection', function () {
  console.log('hello world im a hot socket');
});

All 8 comments

http.createServer(app).listen(app.get('port'), function(){})

That's your server. Not:

var server = http.createServer(app);

You're basically creating two http servers, the latter of which is not listening on any port. It's a zombie.

Turn your code into this:

var server = http.createServer(app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});

var io = socket.listen(server);
io.sockets.on('connection', function () {
  console.log('hello world im a hot socket');
});

You are awesome! Thanks!

Lord guille , you are wonderfull, i wasted like 3 or more days to get back on track ,but hats off to you.Thanks alot for helping me ,thanks indeed!

Magnifique!

Thanks guille!

Thanks ^.^ saved my day

Awesome! Thanks!

OMG ! Thanks !

Was this page helpful?
0 / 5 - 0 ratings