问题
I've successfully made a callback with http://socket.io when the client calls the server
socket.on('event', function(data, fn){ fn(null, true); }
I was wondering if its possible to do the same but this time when the server calls the client?
回答1:
The emit
and on
works exactly same on both sides: client and server.
So if you emit to client-socket on server side, then if on client-side you are subscribed to that event, it will trigger it. And vice versa.
What you are confused by is that server has one socket that is listening one, and many connections with socket per client.
While client has only one socket to talk to server.
Examples here: http://socket.io/#how-to-use
Do bi-directional messages, and you need to clearly read them before denying that there is no bi-directional messaging.
来源:https://stackoverflow.com/questions/18396602/socket-io-server-side-callback