Why are you making your TCP socket nonblocking (with the Blocking => 0 parameter)? A nonblocking socket will return if there's nothing to read; I suspect that when you try to read it with my $data=<$sock>, there's no data to read, so it returns false and the whole program exits. I suspect removing this parameter would solve your problem, but I haven't tested it.

You could confirm this by adding debugging output to your program, or running it in the Perl debugger.

I'd also recommend adding more error checking; right now you wouldn't notice if the socket creation failed, or the prints to the socket failed, since you're not checking their return values. Checking the return value from close also sometimes shows errors that were delayed, or caused the socket to close.


In reply to Re: Problems reading back from socket by sgifford
in thread Problems reading back from socket by planet_guru

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.