Phoenix.pm: Net::Telnet

Scott Walters scott at illogics.org
Wed Jan 14 19:56:19 CST 2004


That's truely bizarre. Serial data -> Ethernet -> TCP/IP, all automatically.

The select() stuff is the way to go. You can say, "end the loop when I
haven't gotten any new data in in the last half a second", for example.

-scott

On  0, Matt Alexander <m at pdxlug.org> wrote:
> 
> Yeah...  the problem is that the remote side doesn't disconnect when it's
> done sending data...  It's an ethernet-to-serial adapter that sends out
> data whenever the device connected to the serial side happens to generate
> new data.  There's no signal that the system has sent all the data it
> currently has.
> 
> 
> 
> On Wed, 14 Jan 2004, Scott Walters wrote:
> 
> > The remote side should disconnect when it is done sending data.
> > Perl insulates you from errors, so it is easy not to ever notice
> > that you've been disconnected. Do this:
> >
> >   while(read $fh, my $stuff, 8192) {
> >      # process $stuff
> >   }
> >
> > read() returns 0 on EOF or undef on error. There is also an eof()
> > built-in that is only valid after the first time you read from a
> > socket (don't do while(!eof($fh)) { read stuff.. }, use a do { } while
> > instead).
> >
> > On  0, Matt Alexander <m at pdxlug.org> wrote:
> > >
> > > On Wed, 14 Jan 2004, Scott Walters wrote:
> > >
> > > > There is an example of raw sockets on phoenix.pm.org website,
> > > > but IO::Socket::INET is about the right level of abstraction for
> > > > what you're doing. Clearly Net::Telnet is too much of the wrong
> > > > abstraction. Raw sockets are usually too little abstraction.
> > > >
> > > > >From the man page:
> > > >
> > > >               $sock = IO::Socket::INET->new(PeerAddr => 'www.perl.org',
> > > >                                             PeerPort => '80',
> > > >                                             Proto    => 'tcp');
> > > >
> > > > You can then print to $sock, $sock->print("foo!\n"), read from it,
> > > > read $sock, my $buffer, 8192, read lines from it, my $line = readline $sock,
> > > > and so on, just like a normal IO::Handle.
> > >
> > > I ended up using raw sockets and I can now grab all the data, but I'm not
> > > sure how to disconnect after a certain period of time.  The device I'm
> > > connecting to doesn't give any indication of when it's done sending data.
> > > So I basically need to grab everything, set an overall time limit of say,
> > > 5 seconds, and then disconnect after that time limit.
> > > Any suggestions?
> > > Thanks,
> > > ~M
> >



More information about the Phoenix-pm mailing list