Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
256 views
in Technique[技术] by (71.8m points)

node.js - Broadcast a message to all clients without using Loops

In my chat app i have public chats and messages should be broadcasted to everyone, I'm using WebSocket in NodeJS.

I saw in Socket.io or other frameworks it iterates over the clients one by one and sends the message, This doesn't seem to be an optimal solution. Is there another way (alternative) to do that without using Loops?
I've also seen others use RabbitMQ in their chat apps, Is RabbitMQ what i want? or What exactly is it used for?

const clients = [...];
clients.forEach(client => {
    client.send("Message!");
});
question from:https://stackoverflow.com/questions/65883132/broadcast-a-message-to-all-clients-without-using-loops

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...