in reply to Perl socket handling problem

Another way to do it...

Here's some client code for a slower responding socket server, or when all the data doesn't show up at once, due to other issues. It sends a chunk, and waits for a response, up to N loops. Small sleeps might be safer than just looping, but hey, everyone works differently. You also could add checks for some termination sequence, or checks for the chunk meeting a fixed size requirement.


my $indata; my $remote = IO::Socket::INET->new( Proto => "tcp", PeerAddr =>'' , PeerPort => $self->{'30000'}, ); if( defined($remote) ) { my $readsize; print $remote $bigdata; my $done = 0; my $zreads =0; while (! $done) { my $tempdata=""; $tempdata = <$remote>; $readsize = length $tempdata; $zreads++ if ($readsize == 0); $done = 1 if ($zreads > 30); $in_data = $in_data . $tempdata; $done = 1 if ($tempdata eq "\n"); } close $remote; }