Localizing $/ may be the source of your problems. If the server doesn't "hang up" the connection, your program may be caught waiting for more data. Unlike a regular file, a socket doesn't hit EOF until the other end hangs up, such as using either close or shutdown.

You could try reading a certain number of lines, or perhaps you are supposed to be watching out for a signal. Maybe it's something like this:
my $buffer; while (my $line = $socket->getline()) { # Maybe this is the "END" line, and if it is, # bail out of the loop because we're done! last if ($line =~ /^END$/); # Otherwise, just tack that stuff onto the buffer. $buffer .= $line; } print "Read: ", $buffer, "\n";
You could very well use <$socket> in place of the IO::Handle getline call. Note that this version will only block until the "END" line is received. The server doesn't have to hang up, and so the connection can remain open for other transmissions.

Footnote:
I honestly shudder every time I see those outrageous loop labels. Maybe they are promoted by shell-shocked veteran Fortran programmers, because over 99% of the time they serve no practical purpose, this single loop being a fine example. If you absolutely need them, by all means, but putting them in there "just because" is nonsense.

In reply to Re: Getting multiline input from a server by tadman
in thread Getting multiline input from a server by nysus

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.