HenningM / express-ws

WebSocket endpoints for express applications
BSD 2-Clause "Simplified" License
878 stars 142 forks source link

[Question] How to send broadcast message? #80

Open 6pm opened 7 years ago

6pm commented 7 years ago

How to send broadcast message for all users? I used before connection.sendUTF(json) with pure node server. Thank you for answer.

textbook commented 7 years ago

You can get the list of all clients per the API docs, then send a message to each one:

ws.getWss().clients.forEach(client => client.send(payload));  
abhishek11210646 commented 6 years ago

what if I have millions connected user. Will it work efficiently?

textbook commented 6 years ago

@abhishek11210646 I wouldn't think so, it's O(n)

skingorz commented 5 years ago

您可以根据API文档获取所有客户的列表,然后向每个客户发送一条消息:

ws.getWss().clients.forEach(client => client.send(payload));  

How to broadcast a message to some specific users

Perodactyl commented 3 years ago

I answered this a bit ago. https://github.com/HenningM/express-ws/issues/140#issuecomment-900628888