- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
试图让我的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/
试图让我的socket_read()在之前已经读取过数据时阻塞。 我需要它等待$ spawn套接字具有新数据(可以相等,即希望它在接收到“FE”时读取两次),然后再次发送。 当没有任何新数据时,如何阻
在 linux 中使用 socket_read() 时,我遇到了一个非常奇怪的行为。 我正在使用缓冲区限制为 2048 的 socket_read。 虽然在我的 Windows 系统上它获得了整个响应
我使用下面的脚本连接到外部PBX服务器并获取调用日志。 但是,它在等于1 log的时间仅返回1刺。因此,我需要刷新多次以获取所有可用的日志。 $socket = socket_create(AF_IN
我最近开始在 PHP 上练习套接字,但遇到了一个我找不到文档的问题。我在 C++ 中看到过类似的情况,但对此没有明确的答案。编码: do { $input = socket_read($cli
我在运行 $data = socket_read($socket, 2048, PHP_BINARY_READ); 应该返回这样的字符串 // $data == ' 1840 kg G 008765
从阅读PHP手册来看,socket_recv和socket_read函数看起来和我一样,这两个函数都从客户端获取数据。 谁能告诉我这两个函数有什么不同? 最佳答案 socket_recv 返回接收到的
我尝试使用 PHP 套接字创建从 C# 应用程序到 PHP 5.3 脚本的 tcp/ip 套接字连接。 C# 应用程序应将 JSON 字符串发送到 PHP 脚本。 我关于 the socket_rea
我想知道如何在 socket_read 调用上设置超时?第一次调用 socket_read 时,它会等待数据发送,如果 5 秒内没有数据发送,我想关闭连接。有帮助吗?我已经尝试过 SO_RCVTIME
我正在学习套接字编程,并尝试使用php。 我想使用客户端连接到套接字服务器,并从客户端读取服务器的响应。 的代码: Server.php: $address="127.0.0.1"; $port=33
我正在尝试从我在 Java 应用程序上编写的套接字读取响应。然而 PHP 只是挂起。这是我用来从套接字读取的代码: while($resp = socket_read($socket, 1000))
编辑: *测试工具中的错误导致我误解了结果。 socket_select() 的工作方式完全如您所料:它确实会等待,直到套接字上的数据准备就绪。但是如果你在客户端关闭连接后调用它,它会报告就绪。原来这
编辑:我已经解决了自己的问题并修复了下面的代码以反射(reflect)这些更改,以防有人遇到同样的困难。此代码适用于 PHP 客户端和 java 服务器连接。 我知道论坛上充斥着这些问题...但是,在
我正在编写一个 PHP 服务器,客户端以特定的字符编码发送数据。现在,我想告诉服务器以相同的字符编码集读写数据。 我应该如何为PHP的socket_read指定字符编码集?和 socket_write
我正在尝试创建一个 PHP 客户端来连接到一个简单的 Java 服务器,发送一些数据,然后接收返回的响应。 Java 服务器在与用 Java 编码的简单客户端交互时响应良好,但是一旦从 PHP 客户端
我用 socket_create()创建套接字资源,然后绑定(bind) IP通过 socket_bind() 向它发送地址,它的工作正常; 但过了一会儿(超过 30 分钟)在行 socket_rea
我是一名优秀的程序员,十分优秀!