Hi, all monks:

I am building tcp client/server based on POE::Wheel::SocketFactory and POE::Wheel::ReadWrite, and I want the server side can detect the event that the client side is disconnected from the internet as soon as possible(like someone pull the wire out, or the wire is loose, but the client side is still alive, so no tcp FIN package is sent to the server ).

Originally, I think I can set a timeout for the connection accepted by POE::Wheel::SocketFactory, So I use 'sockopt' against the client socket generated by the SocketFactory like the code below. onWheelSFSuccess() is the handler of 'SuccessEvent' event in POE::Wheel::SocketFactory :

sub onWheelSFSuccess { my ( $heap, $clientSocket, $peerHostN, $peerPort ) = @_[ HEAP, ARG0, ARG1, ARG2 ]; my $peerHost = inet_ntoa($peerHostN); my $timeout = pack( 'll', 5, 0 ); $clientSocket->sockopt(SO_RCVTIMEO, $timeout ); $clientSocket->sockopt(SO_SNDTIMEO, $timeout ); my $ioWheel = POE::Wheel::ReadWrite->new( Handle => $clientSocket, InputEvent => 'onWheelRWInput', ErrorEvent => 'onWheelRWError', Filter => POE::Filter::Stream->new(), ); ......
but, I got the following error complainted:
Can't locate object method "sockopt" via package "FileHandle"

So, I know, the 'clientSocket' is no longer a socket filehande but just a filehandle, it has lost its socket attributes. But how can I set a time out for this 'clientSocket', so I can let the POE::Wheel::ReadWrite trigger an ErrorEvent if it can't send the message out within the timeout?

Or, Is there a better and more convinent way to detect the disconnection of the client side in POE?


In reply to How to set a timeout for the socket filehandle generated by POE::Wheel::SocketFactory ? by sunshine_august

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.