If the hardware dosn't respond, there is no program in the world that will read anything out of that socket. You need to explain/explore the communication protocol of the hardware device, and find out what it needs to trigger a response. All I can do is make guesses in the dark.

It might be as simple as adding a newline to your send:

$sock->send( "$msg\n" ); # possibly " $msg\r\n " # or send a blank line $sock->send( "\n" );
to tell the hardware you are done sending your line.

You might also try something like this hack to inefficiently read 1 byte at a time

while(my $len = sysread( $sock, my $buffer, 1) > 0) { print "$buffer\ +n"; }
Otherwise, you need to provide much more information about your hardware. Does the hardware have a driver written in c or c++? Can you look at the driver's source code to see what it does? Does the hardware have any driver that works?

Finally, when you use the socket methods send and recv, you are establishing a 1 way-at-a-time protocol. The hardware device might be getting locked into recv mode.

You might be better off using IO::Select on the socket and using syswrite and sysread instead of send and recv.

A simple IO::Select program might look like this:

#!/usr/bin/perl use warnings; use strict; my $sock = new IO::Socket::INET( PeerAddr => $host, PeerPort => $port, Proto => 'tcp', Reuse => 1 ); $sock->autoflush(1); # latest Sockets has this on by default print $sock "log in information"; my $read_set = new IO::Select($sock); my $incoming_data = ""; while (1) { my @ready = $read_set->can_read(.5); foreach my $rh (@ready) { sysread ( $rh, my $line, 1024); $incoming_data .= $line; print "$incoming_data\n"; } }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re^3: Getting stuck reading from a socket by zentara
in thread Getting stuck reading from a socket by punungwe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.