$WaitSec = 10; # to test it's set to 10 sec # later it will be set to 60 # to wait 1 min to send next 1 min bar. @a = @ARGV; $f = (@a) ? $_[0] : "SP1Min.txt"; open (MF, "< $f") or die "can't open $f: $!"; $MIN = ; #read 1. line chomp($MIN); $SEP = ''; # to set Global Seperator &startServer(); ##### subs ######### sub logmsg { print "$0 $$: > @_ < at ", scalar localtime, "\n" if $v; } sub startServer { #use strict; BEGIN { $ENV{PATH} = '/usr/ucb:/bin' } use Socket; use Carp; my $EOL = "\015\012"; my $port = shift || 2345; my $proto = getprotobyname('tcp'); ($port) = $port =~ /^(\d+)$/ or die "invalid port"; socket(Server, PF_INET, SOCK_STREAM, $proto) || die "socket: $!"; setsockopt(Server, SOL_SOCKET, SO_REUSEADDR, pack("l", 1)) || die "setsockopt: $!"; bind(Server, sockaddr_in($port, INADDR_ANY)) || die "bind: $!"; listen(Server,SOMAXCONN) || die "listen: $!"; logmsg "server started on port $port"; my $paddr; $SIG{CHLD} = \&REAPER; for ( ; $paddr = accept(Client,Server); close Client) { my($port,$iaddr) = sockaddr_in($paddr); my $name = gethostbyaddr($iaddr,AF_INET); logmsg "connection from $name [", inet_ntoa($iaddr), "] at port:$port, proto:$proto, iAdr:$iaddr"; print Client "Hello", $name, $EOL; # connected to s.o. #now send every $WaitSec one line of the file. print Client $MIN, $EOL; $t = time; while ( defined($MIN = )) { chomp($MIN); sleep ((time + $WaitSec) - $t); $t=time; print Client $MIN, $EOL; logmsg($MIN); } print Client "End of Session", $EOL; logmsg("File Ende -- Session-Ende, Good Night"); close(MF); exit; } #end for } #end sub #### 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; } } }