in reply to Creating a simple HTTPD in Perl
local $|=1; use IO::Socket; my $PORT = $ARGV[0] || 9000; # pick something not in +use my $server = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $PORT, Listen => SOMAXCONN, LocalAddr => 'localhost', Reuse => 1); unless ($server) { logit "can't setup server",0; exit 0; } while (my $client = $server->accept()) { $client->autoflush(1); my $request = <$client>; chomp $request; #do stuff with the request here, like: if ($request =~ m|^GET /(.*) HTTP/1.[01]|) { # some sort of processing, whatever you want } else { print $client "HTTP/1.0 400 BAD REQUEST\n"; print $client "Content-Type: text/plain\n\n"; print $client "BAD REQUEST ($request)\n"; } close $client; }
|
|---|