i'm reading Network Programming with Perl
there is an example in chapter5:concur rent clients.
the author said if we change "last LOOP unless $from_server=<$ socket>" into a loop like
this will cause a deadlock,this is what the author say
" Now the script hangs after it reads the first line from the server. The FTP server is waiting for us to send it a command, but the script is waiting for another line from the server and hasn't even yet asked us for input, a situation known as deadlock. "
I just don't understand why the script hangs after it reads the first line from the socket if the socket contains more than one line.
there is an example in chapter5:concur rent clients.
Code:
#!/usr/bin/perl
use strict;
use IO::Socket qw(:DEFAULT :crlf);
my $host=shift or die"Usage:gabl.pl host [port]\n";
my $port=shift || 'tcp';
my $socket=IO::Socket::INET->new(PeerAddr=>$host,PeerPort=>$port) or die "can't connect:$!";
my($from_server,$from_user);
LOOP:
while(1){
{
local $/=CRLF;
last LOOP unless $from_server=<$socket>;
chomp $from_server;
}
print $from_server."\n";
last unless $from_server=<>;
chomp($from_user);
print $socket $from_user,CRLF;
}
Code:
while($from_server=<$socket>){
chomp $from_server;
print $from_server,"\n";}
" Now the script hangs after it reads the first line from the server. The FTP server is waiting for us to send it a command, but the script is waiting for another line from the server and hasn't even yet asked us for input, a situation known as deadlock. "
I just don't understand why the script hangs after it reads the first line from the socket if the socket contains more than one line.
Comment