This sounds like a buffering problem - close the socket on the client when you've finished sending data, or use sysread() and syswrite() (and no other IO calls) to access the socket data. I wrote a longer article on this at Socket.pm nonblocking.

Update: This happens because all of perl's standard file operators - including things like eof() - are buffered, and read ahead when called. This usually isn't a problem, but with a filehandle that may block (eg a socket or a pipe), perl may block while reading ahead, so you don't see the data until it finishes. Sometimes you write some data to a socket and close it straight away - you won't see the problem here, as perl will stop reading when it gets the EOF. However, if you are trying to do something interactively, where the client socket stays open, you may find perl blocks before you get all the data that is available. sysread() and syswrite() bypass all this, so you can read right up to the last byte using them :-) Remember to check the return values for errors and EOF.


In reply to Re: When do I stop reading? by ahunter
in thread When do I stop reading? by jen

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.