gpt4 book ai didi

php - socket_read()不阻塞

转载 作者:行者123 更新时间:2023-12-03 12:06:00 30 4
gpt4 key购买 nike

试图让我的socket_read()在之前已经读取过数据时阻塞。
我需要它等待$ spawn套接字具有新数据(可以相等,即希望它在接收到“FE”时读取两次),然后再次发送。

当没有任何新数据时,如何阻止它?

$i=0;
while ($i<10){
//Read and Parse Client input
$input = strtoupper(bin2hex(socket_read($spawn, 1)));
echo $input . "\n";

//Deal with requests
if ($input == "FE"){ //Server Ping
socket_write($spawn, $ping_packet);
echo "Ping Attempt \n";
} elseif ($input == "02"){ //Handshake Request
socket_write($spawn, $handshake_packet);
echo "Handshake Attempt \n";
} elseif($input == "01"){ //Login Request
socket_write($spawn, $kick_packet);
echo "Login Attempt \n";
}
$i++;
}

最佳答案

您可以使用socket_set_block将套接字设置为阻塞。有关如何同时处理大量套接字的信息,请参见socket_select

关于php - socket_read()不阻塞,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11561627/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com