Hi guys, I'm using the code from http://www.perldoc.com/perl5.6.1/lib/Sys/Syslog.html
to write a Socket-Server-Client connection. The Server sends his lines with $EOL = "\015\012", but the client just does not print anything until the server is killed?
This is my code
The SERVER:
$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 = <MF>; #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 = <MF>)) { 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
This server sends every 10 sec one line which is printed as well.
Here is now the Client from the same site, that shoul receive the bars and print them out for now.
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 = <SOCK>; 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 = <SOCK>) ) { print "NIX, "; sleep 1; next; } else { if ($line !~ /End\sof\sSession/) { print "\nGot2: ", $line; sleep 5; next; } else { close (SOCK) || die "close: $!"; exit; } } }
I thank all who take time to read it at least for their effort, Carl

In reply to Socket: I don't get what is sent by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.