Here i use those codes:
// Initial web request.
app.get('/hello', function(req, res) {
// Forward to an io route.
req.io.route('hello')
})
app.io.route('hello', function(req) {
//Here use emit
req.io.emit("world","world");
})它报告的错误如下:
TypeError: Object #<Object> has no method 'emit'
at Object.hello (/Users/wensonsmith/ProjectX/Server/app.js:44:12)
at Manager.io.route (/Users/wensonsmith/ProjectX/Server/node_modules/express.io/lib/index.coffee:65:29)
at Object.request.io.route (/Users/wensonsmith/ProjectX/Server/node_modules/express.io/lib/index.coffee:143:29)
at /Users/wensonsmith/ProjectX/Server/app.js:39:12
at callbacks (/Users/wensonsmith/ProjectX/Server/node_modules/express.io/node_modules/express/lib/router/index.js:160:37)
at param (/Users/wensonsmith/ProjectX/Server/node_modules/express.io/node_modules/express/lib/router/index.js:134:11)
at pass (/Users/wensonsmith/ProjectX/Server/node_modules/express.io/node_modules/express/lib/router/index.js:141:5)
at Router._dispatch (/Users/wensonsmith/ProjectX/Server/node_modules/express.io/node_modules/express/lib/router/index.js:169:5)
at Object.router (/Users/wensonsmith/ProjectX/Server/node_modules/express.io/node_modules/express/lib/router/index.js:32:10)
at next (/Users/wensonsmith/ProjectX/Server/node_modules/express.io/node_modules/connect/lib/proto.js:190:15)req.io.respond没事。
广播也有一些problem.It可以播放,但它不停止后广播。它运行了很长一段时间,然后不返回任何内容,也不返回错误消息。
我的代码是
// Initial web request.
app.get('/hello', function(req, res) {
// Forward to an io route.
req.io.route('hello')
})
// Forward io route to another io route.
app.io.route('hello', function(req) {
req.io.broadcast("world","world");
})发布于 2013-11-24 17:49:13
从堆栈跟踪来看,您发布的代码看起来并不是实际的代码。
但除此之外:据我所理解的express.io,当您将HTTP请求转发给io路由时,io路由应该总是用respond发送回响应;否则,HTTP请求将停止。
所以试试这个:
app.get('/hello', function(req, res) {
req.io.route('hello');
});
app.io.route('hello', function(req) {
// broadcast first...
req.io.broadcast("world","world");
// ...then send back an empty response
req.io.respond();
});为了确保:req.io.broadcast不会将消息发送回发起请求的客户端。如果您想要这样做,请使用app.io.broadcast (见文档)。
发布于 2014-03-01 10:15:53
答复率只有50% ):
.respond使用您的参数“直接”发出,例如:
req.io.respond({hello: 'world'})https://stackoverflow.com/questions/20177184
复制相似问题