[Twisted-Python] checking connection

glyph at divmod.com glyph at divmod.com
Tue Nov 11 18:28:08 EST 2008


On 08:41 pm, 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?

You're confusing two mostly unrelated things.  Pidgin tracks the state 
of your network interfaces by way of dbus notifications from 
NetworkManager, not by "checking every XX minutes".  You could do this 
with Twisted by using the glib2 reactor and the dbus bindings, but 
that's more of a dbus/NetworkManager question than a twisted question. 
I would strongly recommend that you don't bother with this kind of 
connection-tracking.  My personal experience of applications trying to 
use this information (Pidgin included) is mostly that they are buggy and 
have a broken idea of the machine's network interface state because it's 
very hard to understand how this information can be effectively used 
(and NetworkManager itself is not perfect, sometimes reporting incorrect 
results).

Pidgin (and every other networking application in the world) also tracks 
the state of individual network connections (i.e. your connection to an 
IRC server, or to AOL's AIM server) by waiting for notifications from 
their respective sockets.  In Twisted, this is the stuff related to 
connectionLost that JP Calderone already mentioned in his reply to you. 
This is what you should be relying on in your Twisted application.  Even 
if you implement "internet connection" checking with NetworkManager or 
some other platform's equivalent, that's just a hint; you still have to 
pay attention to connectionLost.




More information about the Twisted-Python mailing list