I have a problem with Express.io: I try to create a chat but I am not able to use the Broadcast method.
No error message, but nothing happens.
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 !!");
});
Error 2
WebSocket connection to 'ws://tchat.aws.af.cm/socket.io/1/websocket/n8Jm9Q7YYL8YdPRN4dxU' failed: Unexpected response code: 502
req.io.broadcast broadcasts to all connected clients except the client associated with the request. You should use app.io.broadcast to broadcast to all connected clients.
See the example given : https://github.com/techpines/express.io/tree/master/examples/broadcasting