sunshine_august has asked for the wisdom of the Perl Monks concerning the following question:
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 :
but, I got the following error complainted: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(), ); ......
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to set a timeout for the socket filehandle generated by POE::Wheel::SocketFactory ?
by rcaputo (Chaplain) on Dec 30, 2008 at 06:16 UTC | |
by sunshine_august (Scribe) on Dec 30, 2008 at 06:41 UTC | |
by rcaputo (Chaplain) on Dec 31, 2008 at 02:17 UTC | |
|
Re: How to set a timeout for the socket filehandle generated by POE::Wheel::SocketFactory ?
by BrowserUk (Patriarch) on Dec 30, 2008 at 04:38 UTC | |
by sunshine_august (Scribe) on Dec 30, 2008 at 05:35 UTC | |
by BrowserUk (Patriarch) on Dec 30, 2008 at 10:29 UTC |