funky TCP problems
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > funky TCP problems




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    funky TCP problems  
grocery_stocker


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-23-07 12:17 AM

Given the following
#!/usr/bin/perl -w
use IO::Socket;

my($handle, $line, $kidpid);
$handle =3D IO::Socket::INET->new(
PeerAddr =3D>"137.104.128.2",
PeerPort =3D>"23",
Proto=3D>"tcp",
)
or die "cant connect to port: $!";

$handle->autoflush(1);
print STDERR "[Connected]\n";
die "can't fork: $!" unless defined($kidpid =3D fork());

if($kidpid) {
while(defined($line =3D <$handle> )){
print STDOUT $line;
}
kill("TERM", $kidpid);
}

else {
while(defined ($line =3D <STDIN> )){
print $handle $line;
}
}

When I run it, I get
[cdalten@localhost]$  ./foo.pl
[Connected]

now, when I hit the 'enter' key on my keyboard, I get
?????


University of Wisconsin - Platteville (pine.ucs.uwplatt.edu)

Then after a few seconds, I get
Username:
Error reading command input


However, what I really want to see is
Trying 137.104.128.2...
Connected to uwplatt.edu (137.104.128.2).
Escape character is '^]'.



University of Wisconsin - Platteville (pine.ucs.uwplatt.edu)

Username:



What's my error in logic?






[ Post a follow-up to this message ]



    Re: funky TCP problems  
Sherm Pendley


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-23-07 12:17 AM

grocery_stocker <cdalten@gmail.com> writes:

> now, when I hit the 'enter' key on my keyboard, I get
> ?????
>
>
> university of Wisconsin - Platteville (pine.ucs.uwplatt.edu)
>
> Then after a few seconds, I get
> Username:
> Error reading command input
>
>
> However, what I really want to see is
> Trying 137.104.128.2...
> Connected to uwplatt.edu (137.104.128.2).
> Escape character is '^]'.
>
>
>
> university of Wisconsin - Platteville (pine.ucs.uwplatt.edu)
>
> Username:
>
>
>
> What's my error in logic?

You're simply connecting to a socket and printing what you get back.
The problem is that terminal emulation is not that simple; there are
also control sequences that your app must act upon instead of simply
printing them.

You might want to have a look at the Term::VT102 module on CPAN.

sherm--

--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net





[ Post a follow-up to this message ]



    Re: funky TCP problems  
Alan Curry


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-23-07 12:22 PM

In article <1185145624.206414.244940@d30g2000prg.googlegroups.com>,
grocery_stocker  <cdalten@gmail.com> wrote:
>
>However, what I really want to see is
>Trying 137.104.128.2...
>Connected to uwplatt.edu (137.104.128.2).
>Escape character is '^]'.

The above three lines would normally be printed by the telnet client reporti
ng
on its progress. If you're trying to make a PERL script that behaves exactly
like /usr/bin/telnet, you'll have to print those lines yourself. (Not to
mention the actual handling of the ^] escape)

>
> What's my error in logic?

The basic error is thinking that telnet is a raw TCP stream. It's not. When
you connect to the telnet server, the first few bytes you get are telnet
option negotiation. See RFC854 for the specification, and the Net::Telnet
module for a perly way to deal with that option negoation.

People often use the telnet client to speak to non-telnet servers like FTP o
r
SMTP, which works because the client doesn't attempt any option negotiation
unless you ask it to. Even here, though, it's not acting as a raw TCP
pass-through. It's adding carriage returns (which happens to be the right
thing for FTP and SMTP and several others) and mangling 0xFF bytes.

--
Alan Curry
pacman@world.std.com





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 09:51 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register