Re: fread & EOF

From: Date: Tue, 29 Oct 2002 10:03:54 +0000
Subject: Re: fread & EOF
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-121828@lists.php.net to get a copy of this message
Would not be closing the conection in the perl script enough? Martin Adler wrote:
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();


« previous php.general (#121828) next »