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'


In reply to HTTP::Daemon webserver keeps breaking by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.