#!/usr/bin/perl -wW use threads; use IO::Socket; our $dir = "."; my $sock = new IO::Socket::INET(Listen => 1, Reuse => 1, Proto => 'tcp', LocalPort => $ARGV[0]); while(1) { (threads->new(\&server, $sock->accept()))->detach(); } sub server { my $sock = shift; my $line = <$sock>; $line =~ s/^(GET )(.*) HTTP.*$/$2/gi; my $file = `cat $dir$line`; my $len = length $file; print $sock "HTTP/1.0 200 OK\r\nContent-Length: $len\r\nContent-Type: text/html\r\n\r\n$file"; close($sock); }