Socket.io Server-side callback

拜拜、爱过 提交于 2021-02-09 08:08:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!