[Twisted-Python] How to set host/IP Address for reactor.listenTcp()
Hi, I'm new to Twisted, I only had a limited experience using python and its asyncore/asynchat. I went through Twisted Howto doc. I just realized that reactor.listenTcp() will only take "listening port" as its parameter. If I want to run a Twisted Program on a machine with multiple network cards(NICs) associated with different IP addresses and I only want my program listening on a specific IP address or NIC, is there a way I can pass listening IP address to reactor.listenTcp() so it'll only accept the connections from a certain NIC/IP Address? Thanks a lot for your help! Jian
Quoting jian wu <hellojianwu@gmail.com>:
Hi,
Hi,
I'm new to Twisted, I only had a limited experience using python and its asyncore/asynchat. I went through Twisted Howto doc.
I just realized that reactor.listenTcp() will only take "listening port" as its parameter. If I want to run a Twisted Program on a machine with multiple network cards(NICs) associated with different IP addresses and I only want my program listening on a specific IP address or NIC, is there a way I can pass listening IP address to reactor.listenTcp() so it'll only accept the connections from a certain NIC/IP Address?
You should have a look at this: http://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.I... -- Thomas
Hi Thomas, Thanks a lot for your quick response! Jian On 1/22/07, Thomas Hervé <therve@free.fr> wrote:
Quoting jian wu <hellojianwu@gmail.com>:
Hi,
Hi,
I'm new to Twisted, I only had a limited experience using python and its asyncore/asynchat. I went through Twisted Howto doc.
I just realized that reactor.listenTcp() will only take "listening port" as its parameter. If I want to run a Twisted Program on a machine with multiple network cards(NICs) associated with different IP addresses and I only want my program listening on a specific IP address or NIC, is there a way I can pass listening IP address to reactor.listenTcp() so it'll only accept the connections from a certain NIC/IP Address?
You should have a look at this:
http://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.I...
-- Thomas
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Hi everyone, I am putting together a number of servers that will all communicate with each other every 5 or 10 minutes via TCP/IP connections. It occured to me that once a connection has been established I might as well leave it open permanently. Are there any problems/side effects of doing this? Is it better policy to close and re-open the connection every now and then? Also am I correct in assuming that if a computer at one end of a TCP/IPconnection crashes or otherwise becomes unavailable the twisted program at the other end will only know this when it attempts to send a packet to the now crashed computer and, having no reply, gets a timeout. Thanks for your help, John
[ John Pote ]: |Hi everyone, |I am putting together a number of servers that will all communicate |with each other every 5 or 10 minutes via TCP/IP connections. It |occured to me that once a connection has been established I might as |well leave it open permanently. Are there any problems/side effects of |doing this? | Is it better policy to close and re-open the connection every now and | then? One advantage of keeping connections opened is to avoid the 3-way handshake that will take place during connection setup. For a few number of conenctions I see no immediate disadvantage, but I guess it all depends on what one means by "few" and the context. |Also am I correct in assuming that if a computer at one end of a |TCP/IPconnection crashes or otherwise becomes unavailable the twisted |program at the other end will only know this when it attempts to send |a packet to the now crashed computer and, having no reply, gets a |timeout. AFAICT, that *is not* a limitation of Twisted. This is simply the fact that TCP -- while a connection is in silence -- will increment its timers, since the rx end-point is unaware if nothing is sent or if the netpath is congested. cheers, Rod Senra ------------- Rodrigo Senra GPr Sistemas http://www.gpr.com.br
I would implement some sort of keep-alive mechanism for those connections, something that will periodically do some sort of ping/pong sequence (possibly even using TCP's keepalive feature if that is available, anyone know if Twisted can request it on at least some platforms?). (Cf. for instance this http://libkeepalive.sourceforge.net/docs/TCP-Keepalive-HOWTO ) This has at least two advantages, the first being that will be able to know that the other side has gone down, and that you will have to reopen your TCP connection, the second being that there maybe various state-full routers/firewalls in between your communication endpoints that could possibly "age out" your connection if you do not send any packets for some time. The main disadvantage is that you generate data traffic even if you do not actually do anything. On Wed, 2007-02-14 at 17:46 +0000, John Pote wrote:
Hi everyone, I am putting together a number of servers that will all communicate with each other every 5 or 10 minutes via TCP/IP connections. It occured to me that once a connection has been established I might as well leave it open permanently. Are there any problems/side effects of doing this? Is it better policy to close and re-open the connection every now and then?
Also am I correct in assuming that if a computer at one end of a TCP/IPconnection crashes or otherwise becomes unavailable the twisted program at the other end will only know this when it attempts to send a packet to the now crashed computer and, having no reply, gets a timeout.
Thanks for your help, John
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
On Thu, 15 Feb 2007 15:25:56 +0100, Thomas Jacob <jacob@internet24.de> wrote:
I would implement some sort of keep-alive mechanism for those connections, something that will periodically do some sort of ping/pong sequence (possibly even using TCP's keepalive feature if that is available, anyone know if Twisted can request it on at least some platforms?).
(Cf. for instance this http://libkeepalive.sourceforge.net/docs/TCP-Keepalive-HOWTO )
http://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.I... An application-level keepalive may be more appropriate. If communication happens every 5 to 10 minutes anyway, then a separate keepalive doesn't seem very useful. Your application traffic will let you know when the connection is lost. Then you can reconnect and re-send whatever messages you need to. Jean-Paul
Quoting Thomas Jacob <jacob@internet24.de>:
I would implement some sort of keep-alive mechanism for those connections, something that will periodically do some sort of ping/pong sequence (possibly even using TCP's keepalive feature if that is available, anyone know if Twisted can request it on at least some platforms?).
Here is documented the setTcpKeepAlive method: http://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.I... Generally you can enable it in the connectionMade of your protocol. -- Thomas
Thanks for all the quick replies. Very helpful, esp the docs links. Initially I will only be using just a 'few' connections, about 4 to 6. Good point about 'stateful packet inspection' as at least one of the servers will be on my home network connecting to the internet via a netgear router. Thanks again, John Thomas Hervé wrote:
Quoting Thomas Jacob <jacob@internet24.de>:
I would implement some sort of keep-alive mechanism for those connections, something that will periodically do some sort of ping/pong sequence (possibly even using TCP's keepalive feature if that is available, anyone know if Twisted can request it on at least some platforms?).
Here is documented the setTcpKeepAlive method: http://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.I...
Generally you can enable it in the connectionMade of your protocol.
On Fri, 2007-02-16 at 10:34 +0000, John Pote wrote:
Thanks for all the quick replies. Very helpful, esp the docs links. Initially I will only be using just a 'few' connections, about 4 to 6. Good point about 'stateful packet inspection' as at least one of the servers will be on my home network connecting to the internet via a netgear router.
James Knight discovered yesterday that some linksys routers have a 10 minute TCP timeout, and it may well be that netgear boxes are similarly broken. If you can manage it, a more frequent application level ping is worth doing.
It occured to me that once a connection has been established I might as well leave it open permanently. Are there any problems/side effects of doing this?
Some firewalls (also inteligent routers) may drop connections which are inactive for a few (5, 10, depending on configurations) minutes. This especially applies in case masquerading is in place.
participants (8)
-
Itamar Shtull-Trauring
-
Jean-Paul Calderone
-
jian wu
-
John Pote
-
Marcin Kasperski
-
Rodrigo Senra
-
Thomas Hervé
-
Thomas Jacob