[Twisted-Python] checking connection
Hi, I have been trying to find out how to keep checking the connection once the connection is made. Says I have successfully connected to the server, and i want to maintain and check that connection. How can i do that?
On Tue, 11 Nov 2008 12:42:07 -0500, Benny <nebpro@gmail.com> wrote:
Hi, I have been trying to find out how to keep checking the connection once the connection is made. Says I have successfully connected to the server, and i want to maintain and check that connection. How can i do that?
What does it mean to "check" a connection? Jean-Paul
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? On Tue, Nov 11, 2008 at 1:43 PM, Jean-Paul Calderone <exarkun@divmod.com>wrote:
On Tue, 11 Nov 2008 12:42:07 -0500, Benny <nebpro@gmail.com> wrote:
Hi, I have been trying to find out how to keep checking the connection once the connection is made. Says I have successfully connected to the server, and i want to maintain and check that connection. How can i do that?
What does it mean to "check" a connection?
Jean-Paul
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
On Tue, 11 Nov 2008 15:41:37 -0500, Benny <nebpro@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. Jean-Paul
On 08:41 pm, nebpro@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.
Thank you very much for your explanation. I did pay attention to the behavior, and I did noticed that when there is no traffic connection, the connectionLost will be called and it will also called the clientConnectionLost too. I used ReconnectingClientFactory in the clientConnectionLost to ensure that the connection is established, and used the reactor.stop() when i have to stop my application. I really appreciate everyone helps. Thank you very much. On Tue, Nov 11, 2008 at 6:28 PM, <glyph@divmod.com> wrote:
On 08:41 pm, nebpro@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.
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
participants (3)
-
Benny -
glyph@divmod.com -
Jean-Paul Calderone