Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

A Socket problem - successful write, failed read

by true (Pilgrim)
on Jul 19, 2010 at 02:09 UTC ( [id://850192]=perlquestion: print w/replies, xml ) Need Help??

true has asked for the wisdom of the Perl Monks concerning the following question:

I have this new IP2IR device which basically allows me to use my computer to control infrared devices in my home. It is from a company called global cache (in case anyone is interested). The documentation lacks a good 'hello world' but it does come with some test executables. I have been trying to control the device through perl. I have had luck with sending commands via sockets but i cannot read the response from the device. I know the device sends a response (they have a utility which shows me the output). I'm trying to fetch this output via perl. The code below works great until the read socket part. It doesn't return anything.

One more piece of evidence is when i run this tool it gets to the read part and sits there. But if I reset my computer's ip address (changed wifi networks) the response string I was expecting through the socket listen suddenly appeared as the program dies. I am running this on a windows7 machine btw but eventually will end up in unix. Here's the code simplified for illustration.

use strict; use IO::Socket; my $server = "192.168.1.106"; my $sock = new IO::Socket::INET->new( PeerAddr => $server, PeerPort => 4998, Proto => 'tcp', Type => SOCK_STREAM, ); $sock or die "no socket for $_: $!"; $sock->autoflush(1); #Send a device command ending with return (slash r) print $sock "getdevices\r"; #here is where i am stuck... while (<$sock>) { print "$_\n"; }
Thanks for reading! jtrue

Replies are listed 'Best First'.
Re: A Socket problem - successful write, failed read
by BrowserUk (Patriarch) on Jul 19, 2010 at 02:25 UTC

    Try setting $/ = chr(13);.

      Perfecto! thanks again BrowserUk!
      jtrue
Re: A Socket problem - successful write, failed read
by Anonymous Monk on Jul 19, 2010 at 02:16 UTC
    What protocol?
      The device asks for a TCP Protocol
      jtrue
        That is like saying Telephone, you still need to know if the person you're calling expects French, Italian or Esperanto.

        TCP is the transport layer, I was asking about the application layer.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://850192]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-25 15:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found