Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re^5: IO::Socket Listen

by Eliya (Vicar)
on Dec 06, 2011 at 14:26 UTC ( #942040=note: print w/replies, xml ) Need Help??

in reply to Re^4: IO::Socket Listen
in thread IO::Socket Listen

 &#9824;A?42.3< 30D 0.111.3&#9829;) 210 Seconds Delay

Do you mean you're actually getting (i.e. reading/printing) the values on the client side, and then there is the delay?

If so, you probably want to close the socket (or exit the loop) after having gotten the (complete) response.  Otherwise, the while loop with the sysread will continue to repeat until the remote side itself closes the socket (i.e. sysread sees EOF and returns 0).

Replies are listed 'Best First'.
Re^6: IO::Socket Listen
by Secalles (Initiate) on Dec 06, 2011 at 14:45 UTC
    Yes that's it , how can i identify that I have the complete response?

      When you know the length of the expected response (such as 131), you can concat the pieces you get from sysread and check if the resulting string has reached that length.  I said "pieces" because in theory (for example, if the connection has temporarily stalled for some reason), sysread might return prematurely with less than the requested number of bytes. So, to be sure, you'd need some loop + concat:

      my $len = 131; my $resp = ''; while ( sysread $socket, $_, $len ) { $repsp .= $_; last if length($resp) >= $len; }

        Eliya , your code provide some improvements in the performance it dont take 5 minutes anymore it takes between 30sec and 2minutes , is there anyway to make this faster? Thanks!

        Here is my code now

        my $socket = new IO::Socket::INET ( PeerAddr => '', PeerPort => '6008', Proto => 'tcp', ); die "Couldn't connect: $!\n" unless $socket; $data = pack("CccccccCcCC",02,65,63,80,81,76,86,03,100,13,10); if ( $socket ) { print $socket $data ; my $len = 131; my $resp = ''; while ( sysread $socket, $_, $len ) { $resp .= $_; last if length($resp) == $len; } print "$resp\n"; } close($socket);

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://942040]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2018-06-23 10:48 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.