broadcastMessage method
Broadcasts a message to all connected clients except the sender.
This method sends the specified message to all clients connected to the server, except the client that sent the original message.
message: The message to be broadcasted.
sender: The WebSocket client that sent the original message.
Implementation
void broadcastMessage(String message, WebSocket sender) {
for (var client in _clients) {
if (client != sender) {
client.add(message); // Send message to all clients except the sender.
} else {
client.add(
"$message--- From Server"); // Optionally send a modified message back to the sender.
}
}
}