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
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.