there is an example in chapter5:concurrent clients.
Expand|Select|Wrap|Line Numbers
- #!/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;
- }
Expand|Select|Wrap|Line Numbers
- 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.