Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^6: IO::Socket Listen

by Secalles (Initiate)
on Dec 06, 2011 at 14:45 UTC ( #942042=note: print w/ replies, xml ) Need Help??


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

Yes that's it , how can i identify that I have the complete response?


Comment on Re^6: IO::Socket Listen
Re^7: IO::Socket Listen
by Eliya (Vicar) on Dec 06, 2011 at 15:03 UTC

    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);
        Try the unbuffered read() function instead of sysread(). Do not mix buffered and unbuffered reads! That will cause big trouble!

        You should be able with wireshark to tell if the problem is in the receive buffering or in the transmit delay from the other end. I am suspecting however that there is some delay while processing these very short packets. Although the time frame seems to be incredibly long! Can you provide more timing info from wireshark? What happened when you did: $socket->flush(); after the write (in Perl lingo the "print"?

        Update: I was confused.. corrected and also another suggestion posted.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2014-07-12 13:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (240 votes), past polls