yii2-swoole icon indicating copy to clipboard operation
yii2-swoole copied to clipboard

How can I broadcast a message to all connected clients?

Open rovico opened this issue 6 years ago • 0 comments

Hi!

I am newbie in websockets and swoole, herefore I understand, that i may do something wrong. I have a project, where i need to send push messages to all connected websocket clients, for example i need to notify all users that there is new messages or tasks for them.

I expected to get list of all connected clients and then run through that list and send push to each fd... But I cannot do this direct, because server starts in SwooleService. Than i thought, that i need to create a task, that will run cli action, that will send pushes.... I created a mongoDb task and it runs my action, but i still can't get server instance to list clients....

My question is How can I broadcast a message to all connected clients?

Please, Help!

rovico avatar Mar 14 '18 13:03 rovico