Hello Monks, Forgive the title, I would welcome more descriptive titles. I have a vendor application that requires that I telnet to the server/port to control certain functions. I want to automate some functions but seem to be running into some issues. There are 2 commands I want to feed to the program, status and exit. Interactivly this works fine. I type "status" and it lists data. I can type list any number of times. Once I type exit, the telnet session exits. I was hoping to keep the session open and simply type status for as long as I need, then type exit. But instead I seem to have to establish a new session each time. I would appreciate any pointers. Code
use IO::Socket::INET; my $port = 10405; my $host = 'server'; my $socket = IO::Socket::INET->new(PeerAddr => "$host", PeerPort => $port, Proto => "tcp", timeout => 3, Type => SOCK_STREAM) || die " +Could not establish connection : $!\n"; #$SIG{ALRM} = sub { print $socket "exit\n" }; my $header = <$socket>; print $socket "status"; #alarm(1); while(<$socket>) { chomp; print "$_\n"; } print "out of loop\n";
However when I run it from the script below it hangs. I belive it is because I am waiting for input on my socket, but none ever comes. To get around this, I set an alarm for 1 second then print exit In the current form, it hangs for ever. If I uncomment the alarm parts, it works fine.

In reply to telnet to a vendor app hangs by iang

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.