常見問題
如何遍歷全部鏈接
use EasySwoole\EasySwoole\ServerManager;
$server = ServerManager::getInstance()->getSwooleServer();
$startFd = 0;
while (true) {
$connectionList = $server->getClientList($startFd, 10);
if ($connectionList === false || count($connectionList) === 0) {
echo "finish\n";
break;
}
$startFd = end($connectionList);
var_dump($connectionList);
foreach ($connectionList as $fd) {
$server->send($fd, "broadcast");
}
}
如何獲取鏈接信息
use EasySwoole\EasySwoole\ServerManager;
$server = ServerManager::getInstance()->getSwooleServer();
$clientInfo = $server->getClientInfo($fd);
Socket有哪些開發(fā)場(chǎng)景?
- H5 即時(shí)游戲
- 網(wǎng)頁聊天室
- 物聯(lián)網(wǎng)開發(fā)
- 服務(wù)器 UDP 廣播
- 車聯(lián)網(wǎng)
- 智能家居
- WEB 網(wǎng)頁服務(wù)器