如果我启动的 \Swoole\WebSocket\Server ,然后有的请求是http过来的,有的是websocket过来的,都是同一个端口。那我要怎么区别 Server::$connections迭代出来的是http的请求客户端,还是websocket请求的客户端呢?
public function push()
{
$server = $_SERVER['swoole_server'];
foreach($server->connections as $fd)
{
// Swoole\WebSocket\Server::push(): the connected client of connection[2] is not a websocket client or closed
$server->push($fd, "你在干嘛呀!小子!");
}
echo "当前服务器共有 ".count($server->connections). " 个连接\n";
return '';
}
因为有的请求是http过来的,有的是websocket过来的,如果我直接这样foreach去push每个fd,就会报错
Swoole\WebSocket\Server::push(): the connected client of connection[2] is not a websocket client or closed
有办法区分 $server->connections 是http还是websocket么?