<explain>
In this case, the TCP client is gracefully disconnected from the server
<?php
define('BUF_SIZE',10);
$sock = socket_create(AF_INET, SOCK_STREAM, getprotobyname('tcp'));
socket_bind($sock, '127.0.0.1',5200);
socket_listen($sock,1024);
$fp = fopen('./socket_shutdown.php','rb');
$clnt_sock = socket_accept($sock);
while(!feof($fp)) {
$str = fread($fp,BUF_SIZE);
socket_write($clnt_sock,$str,BUF_SIZE);
}
$eof = "\n";
socket_write($clnt_sock,$eof,strlen($eof));
socket_shutdown($clnt_sock,1);
$ret = socket_read($clnt_sock, 100);
printf("Message from client:%s\n",$ret);
socket_close($clnt_sock);
socket_close($sock);
?>
<?php
$clnt_sock = socket_create(AF_INET, SOCK_STREAM, getprotobyname('tcp'));
socket_connect($clnt_sock, '127.0.0.1', 5200);
while (($cnt= @socket_read($clnt_sock, 10,PHP_NORMAL_READ)) !==false) {
file_put_contents('./receive.data',$cnt,FILE_APPEND);
}
print "receive file data".PHP_EOL;
socket_write($clnt_sock, "Tank you");
socket_close($clnt_sock);
?>