Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: IO::Socket::INET, threads, and screwy recv() results

by castaway (Parson)
on Jan 06, 2006 at 09:59 UTC ( [id://521435]=note: print w/replies, xml ) Need Help??


in reply to Re: IO::Socket::INET, threads, and screwy recv() results
in thread IO::Socket::INET, threads, and screwy recv() results

I think you misread the code. To me it looks like he's trying to read from the socket with one thread, and write with the other.. which sounds perfectly valid (not that Ive a clue why one would need threads for it).

C.

Replies are listed 'Best First'.
Re^3: IO::Socket::INET, threads, and screwy recv() results
by BrowserUk (Patriarch) on Jan 06, 2006 at 12:47 UTC

    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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://521435]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-03-28 13:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found