in socket.io 0.6, i have following example code:
var io = require('/usr/lib/node_modules/socket.io');
var server = http.createServer(function(req,res){
var path = url.parse(req.url).pathname;
switch( path ){
....
//core codes
socket.broadcast(data);
}
}).listen(8080);
// ... ...
var socket = io.listen(server);
and everything going ok.
But now i have renew the socket.io to 0.7 and have changed the socket.broadcast to socket.sockets.broadcast.send(data) ;
Got an exception : can not call send of ‘undefined’?
Who can tell me how can i send data to everybody without listening on a certain event?
Maybe here is a way:
clients = new Array();
socket.on('connection',function(socket){ clients.push(socket);}
// ...
for(s in clients) s.send(data);
// ...
does it really needed to do like this way?
Thanks!
In socket.io 0.7 you do:
or to namespaces