Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Perl socket handling problem

by bibo (Pilgrim)
on Oct 01, 2004 at 12:46 UTC ( [id://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.

--bibo

my $indata; my $remote = IO::Socket::INET->new( Proto => "tcp", PeerAddr =>'127.0.0.1' , 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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (8)
As of 2024-04-18 13:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found