xiaochengfu / yii2-swoole

yii2 Swoole 扩展,高度整合异步任务处理、websocket通信、服务端实时推送等服务
46 stars 6 forks source link

How can I broadcast a message to all connected clients? #3

Open rovico opened 6 years ago

rovico commented 6 years ago

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!