Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

HTTP::Daemon webserver keeps breaking

by Anonymous Monk
on May 05, 2006 at 19:41 UTC ( [id://547730]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am trying to write a mini-webserver, with the HTTP::Daemon module. This is my code:
use strict; use HTTP::Daemon; use HTTP::Status; $SIG{PIPE}='go_away'; sub go_away { print "Broken Pipe detected\n" } my $html_docs = "/var/www/html"; open LOG, ">> webserver.log" or die "Unable to open log\n"; LOG->autoflush(1); my $d = HTTP::Daemon->new( LocalAddr => 'localhost', LocalPort => 8080, ) or die; print "Listening...\n"; while (my $c = $d->accept) { while (my $r = $c->get_request) { my $url = $r->url->path; print LOG "$url"; if ($r->method eq 'GET' and $r->url->path eq "/") { $c->send_file_response("$html_docs/index.html"); } elsif ($r->method eq 'GET') { $c->send_file_response("$html_docs$url"); } else { $c->send_error(RC_FORBIDDEN) } } $c->close; undef($c); }
It's ok, but when I try to browse it, it show me the broken pipes, but don't exit. But some images don't load in the browser. So, I try to reload the page sometimes and then, seems that it stops working (but still running in the console). What is happening? Thanks

2006-05-05 Retitled by Corion, as per Monastery guidelines
Original title: 'Webserver'

Replies are listed 'Best First'.
Re: HTTP::Daemon webserver keeps breaking
by shonorio (Hermit) on May 05, 2006 at 20:02 UTC
    I'm not answering your question, just suggesting you on other solution that maybe will improve your code. Have you see POE ? Try 'Simple Web Server' cookbook !

    Solli Moreira Honorio
    Sao Paulo - Brazil
Re: HTTP::Daemon webserver keeps breaking
by philcrow (Priest) on May 05, 2006 at 21:08 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-04-25 08:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found