fread & EOF
| From: | Martin Adler | Date: | Mon, 28 Oct 2002 21:28:03 +0000 |
| Subject: | fread & EOF | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-121780@lists.php.net to get a copy of this message | ||
Hi,
this php-script should read from a server (that i've written in perl) until
it receives the EOF signal.
My server sends the EOF-signal by
print $client "\n\004"; # \004 = EOF
to my script but fread wouldn't stop reading
and i don't have any ideas why.
Is php using an other sign for EOF?
------ php script - client
<?
$server = 'myserver';
$command = "some commands";
?>
<html>
<head>
<title></title>
</head>
<body marginwidth="30" marginheight="30">
<table width="40%" cellpadding="4" cellspacing="2">
<tr>
<td bgcolor="#c0c0ff" valign="top">Sende Kommando:</td>
<td bgcolor="#99ff99" valign="top"><? $fd = fsockopen($server, 2202,
&$errno,
&$errstr, 30); echo $command;?></td>
</tr>
<tr>
<td bgcolor="#c0c0ff" valign="top">Erhaltene Daten:</td>
<td bgcolor="#99ff99" valign="top">
<?
echo nl2br(fread($fd, 2048));
fputs($fd, "$command\n\004");
fclose($fd);
?>
</td>
</tr>
</table>
</body>
</html>
------ perl script - server
#!/usr/bin/perl -w
use IO::Socket;
# set record seperator to EOF
$/ = "\004";
$sock_port = 2202;
$sock = IO::Socket::INET->new(LocalPort => $sock_port,
Type => SOCK_STREAM,
Reuse => 1,
Listen => 10) # oder SOMAXCONN
or die "can't create local socket: $@\n";
while($client = $sock->accept()) {
print $client "some output \n";
# terminate client-reading by sending EOF
print $client "\n\004";
chomp($rec = <$client>);
# do something with $rec
$client->close();
}
$sock->close();