我从套接字读取时遇到了一些问题。基本上,我可以连接到机器没有错误。我可以没有错误地写入机器。我似乎无法阅读输出。
以下是我正在做的事情:
$header1 = chr(0xFF).chr(0xFB).chr(0x1F).chr(0xFF).chr(0xFB).chr(0x20).chr(0xFF).chr(0xFB).chr(0x18).chr(0xFF).chr(0xFB).chr(0x27).chr(0xFF).chr(0xFD).chr(0x01).chr(0xFF).chr(0xFB).chr(0x03).chr(0xFF).chr(0xFD).chr(0x03).chr(0xFF).chr(0xFC).chr(0x23).chr(0xFF).chr(0xFC).chr(0x24).chr(0xFF).chr(0xFA).chr(0x1F).chr(0x00).chr(0x50).chr(0x00).chr(0x18).chr(0xFF).chr(0xF0).chr(0xFF).chr(0xFA).chr(0x20).chr(0x00).chr(0x33).chr(0x38).chr(0x34).chr(0x30).chr(0x30).chr(0x2C).chr(0x33).chr(0x38).chr(0x34).chr(0x30).chr(0x30).chr(0xFF).chr(0xF0).chr(0xFF).chr(0xFA).chr(0x27).chr(0x00).chr(0xFF).chr(0xF0).chr(0xFF).chr(0xFA).chr(0x18).chr(0x00).chr(0x58).chr(0x54).chr(0x45).chr(0x52).chr(0x4D).chr(0xFF).chr(0xF0);
$header2 = chr(0xFF).chr(0xFC).chr(0x01).chr(0xFF).chr(0xFC).chr(0x22).chr(0xFF).chr(0xFE).chr(0x05).chr(0xFF).chr(0xFC).chr(0x21);
$fp = pfsockopen('ServerName',$port,$errno,$errstr,35);
if(!$fp) {
echo '<p>Error connecting to system.</p>';
echo $errstr . ' (' . $errno . ')';
} else {
fputs($fp, $header1);
sleep(1);
fputs($fp, $header2);
sleep(1);
fputs($fp, "99\r");
sleep(3);
$read = fread($fp, 128);
$pos = socket_get_status($fp);
echo '<pre>';
var_dump($pos);
echo '</pre>';
//$read = fread($fp,$pos["unread_bytes"]);
//$read = str_replace("\n","<br>",$read);
//$explode = explode("\"",$read);
}
fclose($fp);
对我来说真正奇怪的是socket_get_status()的未读字节为0,但EOF为false。似乎与我相当矛盾。
array(7) {
["stream_type"]=>
string(14) "tcp_socket/ssl"
["mode"]=>
string(2) "r+"
["unread_bytes"]=>
int(0)
["seekable"]=>
bool(false)
["timed_out"]=>
bool(false)
["blocked"]=>
bool(true)
["eof"]=>
bool(false)
}
有没有人知道为什么我无法获得输出?
谢谢!
答案 0 :(得分:0)
我调查了'阻止'值,发现了问题。
基本上,当阻塞== true时,如上所述,那么返回值将等待变为可用。将其设置为未阻止意味着将立即返回该值。
stream_set_blocking($fp, 0);