[Twisted-Python] checking connection
exarkun at divmod.com
Tue Nov 11 17:08:26 EST 2008
On Tue, 11 Nov 2008 15:41:37 -0500, Benny <nebpro at gmail.com> wrote:
>Thank you very much for the response. I am still new with twisted so please
>bare with me.
>What I mean by checking connection is something like instant messenger (i.e.
>pidgin) do in some interval time. Pidgin is checking for internet connection
>every xx minutes to see if the computer still connected to the internet. So
>I am wondering if twisted can do the same thing. Once it is connected (i.e.
>connectionMade), can we tell if that connection still alive or not every xx
>minutes? Is twisted maintain persistent connection?
Just as `connectionMade´ is called when the connection is created, there
is another method - `connectionLost´ which is called when the connection
goes away. You don't need to do any checking.
The only caveat is that because of the way TCP works, if no attempt is
made to send traffic over a connection, it's possible for the connection
to be lost but for your application to never be notified of this. However,
as long as you're trying to send traffic, you won't encounter this case.
If your application needs to be idle for a long period of time, then you
might want to send "keep alives" - any kind of allowed traffic which has
no actual consequence other than to send some traffic. This way you'll
get `connectionLost´ even if you're otherwise idle.
More information about the Twisted-Python