scott at illogics.org
Wed Jan 14 19:48:08 CST 2004
They almost certainly disconnect you when they're done sending stuff,
but if you really want to time-out, use select:
my $readbits = 1 << fileno($fh);
select(my $readbitsout = $readbits, undef, undef, 0.5); # half a second
read $fh, my $buf, 8192;
You'd want to do something like that in loop. See the example in
perldoc -f select - this is a gross simplification. If you did it in a
loop, you'd want to actually test when the select timed out rather than
got data in.
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?
More information about the Phoenix-pm