php socket读取数据显示问题
现在用php连接socket后得到的buffer可以打印出来,网页上的显示如下面所示:
接收到的数据如下所示:
response was:1
response was:1
response was:1
response was:1
response was:1
response was:1
response was:1
现在是向把这个buffer填写到一个文本框中,并一直刷新,不知道怎么实现,请大神们帮助。下面是我的代码!
if(isset($_POST['button'])){
echo "接收到的数据如下所示:";
echo "
";
$port=$_POST["t2"];
$host=$_POST["t1"];
set_time_limit(0);
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)or die("Could not create socket\n"); // 创建一个Socket
$connection = socket_connect($socket, $host, $port) or die("Could not connet server\n"); // 连接
//$connection = socket_connect($socket, "127.0.0.1", 7777) or die("Could not connet server\n"); // 连接
socket_write($socket, "hello socket") or die("Write failed\n"); // 数据传送 向服务器发送消息
ob_end_flush();
//echo str_pad(" ", 256);
while($buffer=socket_read($socket,1,PHP_NORMAL_READ)){
echo "response was:".$buffer."\n";
echo "
";
flush();
}
socket_close($socket);
}
if(isset($_POST['button2'])){
socket_close($socket);
}
?>