Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Perl socket handling problem

by bibo (Pilgrim)
on Oct 01, 2004 at 12:46 UTC ( #395614=note: print w/replies, xml ) Need Help??

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; }

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://395614]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2022-05-20 23:32 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (76 votes). Check out past polls.