#!/usr/bin/perl -w use strict; use threads; use HTTP::Daemon; $|++; my $coreDaemon = HTTP::Daemon->new(LocalPort=>90) or die $!; my $connectno = 0; print "Listening..."; while(my $c = $coreDaemon->accept){ while (my $r = $c->get_request) { if ($r->method eq 'GET') { my ($thrd) = threads->create(\&GetHandler,$c, ++$connectno); $thrd->detach; #$c->send_file_response("c://temp//foo.dat"); } else { #$c->send_error(RC_FORBIDDEN) $c->send_file_response("c://temp//failed.dat"); } } } #from the old code sub GetHandler { my ($connex, $connectno) = @_; my $peeraddr = $connex->peeraddr; prin2log( "Connection $connectno started."); $connex->send_file_response("c://temp//foo.dat"); prin2log( "Connection $connectno finished."); #sleep 1 while ($connex->connected); $connex->close; prin2log( "Connection $connectno closed.\n"); } #STDOUT messages will now go to this (non-filelocked) file sub prin2log { my ($str) = @_; open(H,qq|>>c:\\temp\\foo.log|) or die qq|Cannot write to log: $!|; print H $str . qq|\n|; close(H); }