Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

telnet to a vendor app hangs

by iang (Sexton)
on Sep 15, 2006 at 19:29 UTC ( [id://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!

        jdtoronto

      Hi,

      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.

      Regards,

      fmerges at irc.freenode.net
Re: telnet to a vendor app hangs
by aquarium (Curate) on Sep 16, 2006 at 14:58 UTC
    as an aside...as your question has already been answered...you 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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-20 03:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found