服务器端提示:GET /socket.io/socket.io.js 404 1ms 代码如下:express自动创建的 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(app.router); app.use(express.static(path.join(__dirname, ‘public’)));
// development only if (‘development’ == app.get(‘env’)) { app.use(express.errorHandler()); }
app.get(’/’, routes.index); app.get(’/users’, user.list);
http.createServer(app).listen(app.get(‘port’), function(){ console.log('Express server listening on port ’ + app.get(‘port’)); });
var io = require(‘socket.io’).listen(app);
模板文件 doctype 5 html head title= title link(rel=‘stylesheet’, href=’/stylesheets/style.css’) script(type=‘text/javascript’,src=‘socket.io/socket.io.js’) script(type=‘text/javascript’,scr=’/javascripts/jquery-1.9.1.min.js’) script(type=‘text/javascript’,src=’/javascripts/client.js’) body block content
后面两段代码换成这样试试:
var server = http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
var io = require('socket.io').listen(server);