node.js - Socket.io emit callback not firing on server side? -
my server emits events properly, emit callback never works. in following, nothing logged on console:
server:
io.sockets.emit('delete hint', {id: id}, function(data){ console.log('callback'); });
client:
socket.on('delete hint', function(data){ // display message before deleting $('#' + data.id).fadeout(function(){ $(this).remove(); }); });
i've tried client side code function(data, fn) in case callback needed included on receiving function.
i'm using windows , command prompt shows following when socket.io emitting event:
websocket writing 5:::{"name":"delete hint", "args":[{"id":"1"}, null]}
i can't figure out problem is, doing wrong?
a callback executed on sender computer when receiver computer calls
have @ code:
server:
io.sockets.on('connection', connectionfunc); function connectionfunc (socket) { socket.emit('delete hint', "data client", callthis); } //this function executed when client calls function callthis (datafromclient){ console.log("call fired: " + datafromclient); }
client:
socket.on('delete hint', function(data, callback) { console.log("i received: "+ data); // call fire when u next line runs callback("the callthis function on server run"); });
you can opposite way.
Comments
Post a Comment