#!/usr/bin/env node var debug = require('debug')('my-application'); var app = require('../app'); app.set('port', process.env.PORT || 3000); var server = app.listen(app.get('port'), function() { debug('Express server listening on port ' + server.address().port); }); var chat = require('socket.io')(server); console.log(chat) io.on('connection', function(socket){ console.log('a user connected');})
我用的是express3 在www文件里添加了
var chat = require('socket.io')(server); console.log(chat) io.on('connection', function(socket){ console.log('a user connected');})
为什么说io未定义呢??
按照你的写法,你应该用
chat.on('connection',......
标准的文档示范
Using with the Express framework
Server (app.js)
Client (index.html)
引入socket.io.js了?