1. You read the data from the client socket. Essentially, the order goes something like this:
  1. the server accepts a request from the client and receives a filehandle
  2. the server reads from the filehandle just as it would from any filehandle (ie., using <>, or read, etc.)
  3. you read the GET or POST line, then the request headers, then a blank line (end of headers); you should look for a Content-Length header, which will tell you how long the POST content should be. Then read that much content.
2. I'm not sure exactly how you can trap a client closing the socket; do you mean if the socket is closed normally, or do you mean if the socket is closed because the client hit the Stop button, for example? In the former case, you should basically close the socket once you've written out the response, I think. In the latter case, I *think* you can try to catch a $SIG{PIPE} on write attempts to the client. So set up a $SIG{PIPE} to catch such writes and close the socket.

You might also take a look at HTTP::Daemon (part of LWP), if not to use it, then just to study it for your own uses.


In reply to Re: Questions on socket by btrott
in thread Questions on socket by Delfer

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.