Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: about read HTTP header.

by takshaka (Friar)
on Jun 29, 2000 at 11:54 UTC ( [id://20337]=note: print w/replies, xml ) Need Help??


in reply to about read HTTP header.

Use sysread and alarm to time out the client if necesary. The example below is pretty much straight from the alarm entry in perlfunc.
#!/usr/bin/perl -w use strict; use IO::Socket; my $server = IO::Socket::INET->new(LocalPort => 6969, Type => SOCK_STREAM, Proto => 'tcp', Reuse => 1, Listen => 10, ) or die "Can't create listener socket: $!\n"; while ( my $client = $server->accept() ) { my ($data, $buf); my $timeout = 10; eval { local $SIG{ALRM} = sub { die "alarm\n" }; alarm $timeout; while (sysread $client, $buf, 1024) { $data .= $buf; last if $data =~ /(?:\015?\012){2}/; # reset timeout if we read data alarm $timeout; } alarm 0; }; if ($@) { die unless $@ eq "alarm\n"; } # do stuff with $data print ">>$data<<\n"; }
I imagine HTTP::Daemon would do all this stuff for you.

Of course, a line without the \015\012 (or at least \012) terminator isn't a valid HTTP request, so you shouldn't bother looking at it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://20337]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-24 08:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found