【发布时间】:2014-10-31 06:49:27
【问题描述】:
我希望能够从我的快速路由文件向连接到 socket.io 服务器的客户端发送数据。
我的 app.js 看起来像这样:
var express = require('express');
var app = express();
//routes
require('./routes/test')(app);
// starting http server
var httpd = require('http').createServer(app).listen(8000, function(){
console.log('HTTP server listening on port 8000');
});
var io = require('socket.io').listen(httpd, { log: false });
io.on('connection', function(socket){
socket.join("test");
socket.on('message', function(data){
.....
});
});
module.exports = app;
我的 test.js 文件:
module.exports = function(app){
app.post('/test', function(req, res){
.....
//I would like here be able to send to all clients in room "test"
});
};
【问题讨论】: