node.js + express 使用socket.io 客户端出现socket.io.js 404的问题解决

最近学习node.js socket.io遇到如题问题,在百度google尝试stackoverflow中的几个解决方法未果后,发现控制台上有如下提示“Socket.IO's .listen() method takes an http.Server instance...https://github.com/visionmedia/express/wiki/Migrating-from-2.x-to-3.x”,详细情况如下:

Socket.IO's .listen() method takes an http.Server instance as an argument. As of 3.x, the return value of express() is not anhttp.Server instance. (See the Application function section above.) To get Socket.IO working with Express 3.x, make sure you manually create and pass your http.Server instance to Socket.IO's .listen() method.

var app = express()
  , http = require('http')
  , server = http.createServer(app)
  , io = require('socket.io').listen(server);

server.listen(3000);

在IO的listen方法参数改为http.createServer后便可解决。


posted @ 2012-11-04 20:02  行陌路  阅读(547)  评论(0编辑  收藏  举报