我对Express.io有一个问题:我试图创建一个聊天,但我不能使用Broadcast方法。
没有错误消息,但什么也没有发生。
app.js
var express = require('express.io')
, index = require('./routes/index.js')
, http = require('http')
, path = require('path');
var app = express();
app.configure(function(){
//configure options
});
app.http().io();
app.get('/', index.index);
app.io.route('ready', function(req) {
req.io.broadcast('newUser');
});
app.listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});user.js
io = io.connect();
io.emit('ready');
io.on('newUser', function(data) {
console.log("New user !!");
});误差2
WebSocket connection to 'ws://tchat.aws.af.cm/socket.io/1/websocket/n8Jm9Q7YYL8YdPRN4dxU' failed: Unexpected response code: 502 发布于 2013-03-16 16:46:41
req.io.broadcast向所有连接的客户端广播,但与请求关联的客户端除外。您应该使用app.io.broadcast向所有连接的客户端广播。
参见给出的示例:https://github.com/techpines/express.io/tree/master/examples/broadcasting
https://stackoverflow.com/questions/15443779
复制相似问题