2 u010803887 u010803887 于 2017.01.04 09:01 提问

php socket编程警告,socket_read不知道什么原因,请大神解答 5C

Warning: socket_read(): 3 is not a valid Socket resource in
/home/work/www/..............php on line 28

源码如下:
<?php

date_default_timezone_set("PRC");

class SocketClient {

var $m_targetip;
var $m_targetport;
var $m_response;

function __construct( $targetip, $targetport ) {
$this->m_targetip = $targetip;
$this->m_targetport = $targetport;
}
public function sendAndGetMessage($sengMess){

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_set_option($socket,SOL_SOCKET,SO_RCVTIMEO,array("sec"=>1, "usec"=>0 ) );
socket_set_option($socket,SOL_SOCKET,SO_SNDTIMEO,array("sec"=>3, "usec"=>0 ) );
if ($socket < 0) {
$this->m_response = "socket creat failed: " . socket_strerror($socket);
}
$result = socket_connect($socket, $this->m_targetip, $this->m_targetport);
if ($result < 0) {
$this->m_response = "socket connection failed: " . socket_strerror($socket);
}
socket_write($socket, $sengMess, strlen($sengMess));
while ($this->m_response = socket_read($socket, 2048)) {
echo $this->m_response;
socket_close($socket);
}
}

}
?>

第28行是:socket_read($socket, 2048)
请问为什么会有这个warning信息啊?

1个回答

dabocaiqq
dabocaiqq   2017.01.14 23:19
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!