如何在同一个端口上使用 ExpressJS 和 Socket.io? [英] How to use ExpressJS and Socket.io on a same port?
问题描述
在第三个版本的 ExpressJS express.createServer() 更改为 express() 这个变化使得在同一个端口上绑定 socket.io 变得困难.也许有人可以找到可靠的决定.
In the third version of ExpressJS express.createServer() changed to express() this changes makes difficult to bind socket.io on a same port. Maybe somebody could find robust decision.
现在,这不起作用:
var express = require('express')
, app = express.createServer()
, io = require('socket.io').listen(app);
我目前的工作流程:https://gist.github.com/3596852
推荐答案
中有描述socket.io github 页面(如 @Golo 在您的评论中说明):
It's described on the socket.io github page (as @Golo stated in your comment):
var app = express()
, server = require('http').createServer(app)
, io = io.listen(server);
server.listen(80);
这有效,我让它运行.
可能Golo忘记的是将listen从app.listen(80)
改为server.listen(80)
.我也一直在为此挣扎,直到我意识到我的愚蠢错误.
Probably what Golo have forgotten is to change the listen from app.listen(80)
to server.listen(80)
. I've struggled with this too until I realised my stupid mistake.
这篇关于如何在同一个端口上使用 ExpressJS 和 Socket.io?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!