in reply to Re^2: Terminal across network
in thread Terminal across network

Ah, that makes some more sense. You mean you would like a window, like a normal terminal, in which the user of your script can type commands, that then happen on the machine you are connected to?

If I understood correctly now, then you don't need to start a different program to achieve this, you can just get your perl script to 'listen' on STDIN, and to the telnet socket. When the user types something in the window that the perl script is running in, the script sends it to the remote machine via the telnet socket. The answer comes back via the telnet socket, and is printed to STDOUT in the normal way. Does that make sense? And is it enough?

Coincidentally, I have written several programs of this type. im2 is one of them (but it's code is complex).

What you need are: IO::Socket::INET for the telnet connection (or maybe Net::Telnet) and IO::Select to check whether STDIN or the socket have data waiting, and deal with it appropriately.

Is that enough to start with?

C.

Replies are listed 'Best First'.
Re^4: Terminal across network
by rockmountain (Sexton) on Oct 21, 2004 at 09:12 UTC
    Thanx for the rejoinder. I really appreciate. Now the requirement is clear to me. Let me work on it and come up with some code. However, it would be very kind of you, if you can direct me to more low level design. I mean in which machine perl script should be executed, how should I process inputs in STDIN. Should the window should be created by perl script.Frankly speaking, picture is not crystal clear to me.
    cheers Rock
      Here's a snippet from one I wrote earlier. (A perl telnet client actually, which seems to be essentially what you want) :
      my $sockets = new IO::Select(); $sockets->add(\*STDIN); my $tel = new IO::Socket::INET( PeerAddr => $hostname, PeerPort => $port, Proto => 'tcp', Timeout => 60 ); die "Can't connect to $hostname ($!)" unless $tel; $sockets->add($tel); while(1) { my @handles; @handles = $sockets->can_read(0.5); foreach $handle (@handles) { if($handle == $tel) { $data = <$tel>; last if(!$data); print STDOUT $data; } elsif ($handle == \*STDIN) { $line = <STDIN>; chomp($line); if ($line eq 'q' || $line eq 'quit') { $finish = 1; last; } else { print $tel $line."\r\n"; } } } }
      I've simplified it some, you will need to probably read from the telnet socket using recv instead of <>, since this will hang when telnet sends lines without endling newline characters (which it is apt to do).

      C.

        Started working on the project. It seems I am looking for something like this. "http://www.broadwayinfo.com/" Any inputs are welcome.
        cheers! Rock