Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

telnet to a vendor app hangs

by iang (Sexton)
on Sep 15, 2006 at 19:29 UTC ( #573232=perlquestion: print w/replies, xml ) Need Help??
iang has asked for the wisdom of the Perl Monks concerning the following question:

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.

Replies are listed 'Best First'.
Re: telnet to a vendor app hangs
by VSarkiss (Monsignor) on Sep 15, 2006 at 19:57 UTC
      Unbeliveable.... How simple was that. Thanks very much!
        So you have discovered one of the unwritten rules, if at first you don't succeed, it is likely because you didn't spend enough time at CPAN yet!



      Update: this should be a reply to VSarkiss and his/her recommendation to use Net::Telnet

      In fact, I use it, to connect to some low level hardware via telnet, and without any problem, just works.

      The disconnecting problem could be solved by keeping alive the connection. Some people, set an inactivity timeout, when reached, disconnects the client.


      fmerges at
Re: telnet to a vendor app hangs
by aquarium (Curate) on Sep 16, 2006 at 14:58 UTC
    as an your question has already been could use a utility such as netcat to open a separate "feeding" process, and open another netcat reading process. this way you separate the two interactions if it makes more sense in the app to do so.
    the hardest line to type correctly is: stty erase ^H

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://573232]
Approved by VSarkiss
and the pool shimmers...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2017-02-21 19:25 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (317 votes). Check out past polls.