Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Having failed to locate anything useful via search, chatterbox or the IO::Select, IO::Socket, IO::Socket::INET and Socket docs, I'm forced to waste a SOPW question on it. What is the best/easiest way to detect when the other side of a socket has closed?

Some background: I'm writing a Perl server to work with Java client(s) using IO::Select and IO::Socket::INET. I read from the socket using sysread. I know that IO::Select concludes that a closed socket is constantly waiting to be read from... how I ran into that information I no longer recall, however I'm not entirely certain how to tell if it's closed or not.

I have tried $handle->connected as described in IO::Socket, however, it never seems to return false.

I realize I could have written this a little more clearly, but I'm afraid this will have to do... Thank you for reading, even if you don't know the answer. This is my first foray into networking and communications aside from writing CGI/mod_perl scripts (and we all know those don't really qualify) so any generic tips would be appreciated... In fact, while you're here, anyone know how latency/LAG would affect these kinds of things? (Ie: would sysread give up if lag held up part of a message?)

Thank you



My code doesn't have bugs, it just develops random features.

Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)


In reply to Detecting a closed socket by Flame

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2021-06-15 12:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (72 votes). Check out past polls.

    Notices?