Hi, I have a forking server that uses standard sockets ( use Socket ) and accepts new connections like:
my $client = accept( SESSION, SOCK );
When we accept a new session, we can read and write to the socket through the <SESSION> filehandle. Like so:
while( $newmessage = <SESSION> ){ #do something }
or
print SESSION "Here is your reply\n";
Everything works great, except I am not sure how to detect a dropped connection when working with the filehandle that I got from accept().

Once the client connects, the server starts processing some information and does not talk on the socket for a while. Sometimes the client decides they dont want to wait for results, so they disconnect. I would like to know when this happens so that I can stop processing the request. I dont mind checking it every couple of iterations, but I don't know the procedure.

I tried googling but nothing useful came back right away, so I am putting it in your hands!

Thanks

20050316 Edit by ysth: p and code tags


In reply to Detecting Dead Socket Connection by scmason

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.