Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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).


Comment on Re^5: IO::Socket Listen
Download Code
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 => '192.168.11.244', 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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2014-12-22 23:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (133 votes), past polls