use strict; use Socket; my $v = 1; my ($remote,$port, $iaddr, $paddr, $proto, $line); $remote = shift || 'localhost'; $port = shift || 2345; # random port if ($port =~ /\D/) { $port = getservbyname($port, 'tcp') } die "No port" unless $port; $iaddr = inet_aton($remote) || die "no host: $remote"; $paddr = sockaddr_in($port, $iaddr); $proto = getprotobyname('tcp'); socket(SOCK, PF_INET, SOCK_STREAM, $proto) || die "socket: $!"; connect(SOCK, $paddr) || die "connect: $!"; logmsg("3Remote:$remote, Port:$port, Proto:$proto"); # This message is print, so I do get here! # At the same tiome the server starts sending bars while (1) { $line = ; print "\nGot1: ", $line; # until the server is killed nothing appears. # Then it prints all the time in a new line: Got1: NIX .. if ( !defined($line) ) { #if ( !defined($line = ) ) { print "NIX, "; sleep 1; next; } else { if ($line !~ /End\sof\sSession/) { print "\nGot2: ", $line; sleep 5; next; } else { close (SOCK) || die "close: $!"; exit; } } }