Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^4: IO::Socket Listen

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

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

I have already read the spec , the device is a High Power Amplificator and i'm sending commands to another equipment that controls the HPA called controller,acording to the spec i have to send CR and LF so the controller can understand what i want ( in this case i want the output power level ) to be honest the specs don't have anything useful about the communication.

The lenght of the pakage that i receive is 131 bytes ( it sends 2 pakages one with 63 bytes and another with 68 bytes i'm using wireshark to trace the pakages)

i used Eliya solution and I still have a big delay

Here is the answer of my program

&#9824;A?42.3< 30D 0.111.3&#9829;) 210 Seconds Delay
Changed 1000 to 131 and 2000 but still no fast response
while ( sysread $socket, $_, 131 ) { # 2000 , 1000 print $_; }

Comment on Re^4: IO::Socket Listen
Select or Download Code
Re^5: IO::Socket Listen
by Eliya (Vicar) on Dec 06, 2011 at 14:26 UTC

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

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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (17)
As of 2014-07-11 15:29 GMT
Find Nodes?
    Voting Booth?

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

    Results (230 votes), past polls