Well maybe, but it is very confusing code.

He makes a client style connect to a remote system and port. He then passes the socket, without having checked whether the connection succeeded to two threads.

One of those threads labelled 'sender', sits in a tight loop reading from <> (presumably intended to be STDIN) and sends whatever it reads to the remote system. It never checks whether the socket is connected, or if it is still connected.

The other thread, labelled 'listener' despite that it does use 'listen', sits and attempts to receive anything that arrives on the the port and echo it to STDOUT. This does check whether the port is connected, but just then just falls off the end of the thread. It also just dies if the recv fails. In either case, there is no attempt to coordinate termination with the sender thread, which will just continue to attempt to read and send forever.

The OP claimed that "If I do the same test without threads it works fine", but with an absence of any calls to listen, connect or accept, and no coordination between reads and writes, it is very difficult to see how that could ever be.

Essentially, the OP appears to be leaping into threads without making any attempt to understand the basics of socket communications in a non-threaded environment. I had hoped to solicit a response that would allow me to work further in trying to assist him, but he does seem to want to start at the beginning :(


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^3: IO::Socket::INET, threads, and screwy recv() results by BrowserUk
in thread IO::Socket::INET, threads, and screwy recv() results by jettero

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.