How WebSocket server handles multiple incoming connection requests?
上面的链接说明了如何建立tcp连接。但是我仍然想知道如何启用对websocket的并发请求。当前,即使100个连接同时连接,websocket也无法处理它们。
服务器文件:
$server = IoServer::factory(
new HttpServer(
new WsServer(
$app = new Chat()
)
),
8888,
'0.0.0.0'
);
$currentTime = new DateTime(date('Y-m-d H:i:s'));
$obj = new stdClass();
$server->loop->addPeriodicTimer(1,
function ($timer) use ($server, &$currentTime, $app) {
$currentTime = $currentTime->modify('+01 seconds');
/*process ends*/
foreach ($app->clients as $key => $client) {
$client->send(json_encode($currentTime->format('Y-m-d H:i:s')));
}
}
});
$server->run();
客户端文件
var data = null;
conn = new WebSocket('ws://ip:8888');//ip is the ip address
conn.onopen = function(e){
console.log('Client Connected!');
};
conn.onmessage = function(e){
console.debug(e.data);
}
如何在上面的服务器文件中启用并发请求?我做错了什么事情使得很难同时处理多个连接吗?