如何使用Web插座服务器发送广播数据?
当事件发生时,我需要从我的BE发送数据,因此我创建了一个事件发射器,在Fucntion中,我想向所有客户端发送广播消息(该消息是对象的数组),这是我的代码,但不幸的是无法正常工作。
emitter.on('readData', function(){
wss.broadcast = function(data) {
wss.clients.forEach(client => client.send(Object));
};
});
I need to send data from my BE to FE when an event happen, so I have created an Event Emitter and in the Fucntion i would like to send a Broadcast message to all the client (the message is an Array of Object), this is my code but unfortunately doesn't work properly.
emitter.on('readData', function(){
wss.broadcast = function(data) {
wss.clients.forEach(client => client.send(Object));
};
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,而不是广播,您正在定义广播的功能。
更多详细信息在这里。
Ok instead of broadcasting, you are defining a function to broadcast.
More details here.