Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Control number of running telnet sessions

by SteveB (Novice)
on Oct 17, 2007 at 09:34 UTC ( #645412=perlquestion: print w/replies, xml ) Need Help??

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

I'm writing a script whereby I will be contolling modem sessions via an Access server to dial out and collect information from remote boxes. As I have a number of modems available to me I want to control the number of sessions that I fire off to get this information. As I telnet to the access server what would be the best control structure to use in perl to do this?
  • Comment on Control number of running telnet sessions

Replies are listed 'Best First'.
Re: Control number of running telnet sessions
by jettero (Monsignor) on Oct 17, 2007 at 10:50 UTC

    To be honest, I don't really understand the question...

    But if there's lots of telnet-ing to be done from one processes.... POE::Component::Client::Telnet will probably help. POE does all the hard work for you. I've had a mixed relationship with POE. Sometimes I find it a little tricky, but when I'm connecting to lots of services from one process, it's really the way to go.


      Basically I have a list of devices that I need to connect to on a daily basis. Using an Access Server with 30 modems I want to manage and control the utilisation of the modems. So when I finish collecting data from a device I'll close down the session and then I want a 'session controller' to start another collection process to a different device. So I utilise the modems as much as possible at all times. The modems are accessed via a pool so I use a telnet and tcp port to initiate a modem connection. Hopefully that explains the background and what I'm trying to achieve better.
Re: Control number of running telnet sessions
by idsfa (Vicar) on Oct 17, 2007 at 15:08 UTC

    If all you need to do is limit the number of simultaneous but otherwise identical connections, Parallel::ForkManager should do the trick. You might have to add a little more logic if you need to use a different target port for each connection, but that's just a pop/push stack.

    my @portlist = qw/10001 10002 10003 10004/; use Parallel::ForkManager; $pm = Parallel::ForkManager->new(scalar @portlist); foreach my $target (@targets) { my $pid = $pm->start and next; my $port = pop @portlist; system("telnet $target $port"); push @portlist, $port; $pm->finish; # Terminates the child process }

    The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. — Cyrus H. Gordon

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://645412]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2020-10-31 16:18 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (290 votes). Check out past polls.