简体   繁体   中英

Socket.io Server-side callback

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM