After 20 minutes of not receiving any data the entire file would appear, ...

I must admit I haven't scrutinized the code (a tad too much for my taste... :), but that problem description, together with no mention of autoflush (or flush) in the entire code, makes me guess you have a buffering issue...

Note that the default buffering mode for most file handles / sockets is block-buffered, which means that an entire block of data (e.g. 4K) must have been processed, before the buffer fills up and is written/flushed to its actual destination.

Also note that $|++ only has an effect on the "currently selected handle", i.e. STDOUT (the default) in your case.  It does not automagically turn on autoflushing for every handle used in the program.

To turn on autoflushing for a specific handle, use

use IO::Handle; ... $fh->autoflush();

See also IO::Handle.


In reply to Re: TCP Forwarding Server by Eliya
in thread TCP Forwarding Server by PhillyR

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.