如何遍历全部链接

  1. use EasySwoole\EasySwoole\ServerManager;
  2. $server = ServerManager::getInstance()->getSwooleServer();
  3. $start_fd = 0;
  4. while(true)
  5. {
  6. $conn_list = $server->getClientList($start_fd, 10);
  7. if ($conn_list===false or count($conn_list) === 0)
  8. {
  9. echo "finish\n";
  10. break;
  11. }
  12. $start_fd = end($conn_list);
  13. var_dump($conn_list);
  14. foreach($conn_list as $fd)
  15. {
  16. $server->send($fd, "broadcast");
  17. }
  18. }

https://wiki.swoole.com/wiki/page/p-connection_list.html

如何获取链接信息

  1. use EasySwoole\EasySwoole\ServerManager;
  2. $server = ServerManager::getInstance()->getSwooleServer();
  3. $fdinfo = $server->getClientInfo($fd);

https://wiki.swoole.com/wiki/page/p-connection_info.html

Socket有哪些开发场景?

h5即时游戏

网页聊天室

物联网开发

服务器udp广播

车联网

智能家居

web网页服务器