node.js - nodejs socket.io server emit with an answer of server on -



node.js - nodejs socket.io server emit with an answer of server on -

if emit serverside imperative code can respond "on" @ clientside?

my problem if user login gets specific users list object.

imagine logs in, gets custom object contents of user b, g , x. problem, users b, g , x each have custom object. of course, on server side.

now tried server side emit send these users. emitted should received on server side on. however, not work.

i tried this

io.sockets.on('connection', function(socket){ socket.on('login', function(){ for(var key in specific_object){ specific_object[key].emit('add user'); } }); socket.on('add user', function(data){ console.log("now please...."); }); });

hopefully can help me :)

update

.jpg)

if understand correctly, may create function , phone call both login , add user events:

function adduser(socket, data) { console.log("now please...."); //do socket , passed info } io.sockets.on('connection', function(socket){ socket.on('login', function(){ for(var key in specific_object){ //specific_object[key].emit('add user'); adduser(specific_object[key], {your: 'data'}); } }); socket.on('add user', function(data){ adduser(socket, data); }); });

node.js socket.io emit

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -