[Twisted-Python] multiple connectTCP bindaddress problem

Chris Laws claws at tpg.com.au
Thu Nov 4 20:45:56 EST 2004


I'm in the process of building a twisted application which will be used to automate control
of processes running on remote machines. 
The basic architecture is a client to many server configuration.
1. many (~30), twisted based, network server applications running on different machines,
2. a client side, twisted based, application which will be used to control and monitor the servers.


This is a small component of a large project and as part of the project we have defined
port ranges which applications can use so as not to interfere with other project applications.
Therefore I need to remain within a certain port range.

The client application uses a twisted client factory to establish the conection handlers.
The machines I am running on have multiple interfaces so I am using the 'bindaddress'
argument in the reactor.connecTCP method to force the client side connection estalishment
to originate from a certain IP:port. I am calling connecTCP for each instance of a server which
I need to conect with. I pass in a different server address each time but leave the 'bindaddress'
the same.

My understanding is that this should create a valid TCP connection to each different server
IP:port address, all originating from the same client IP:Port. Maybe there is a fundamental flaw
in my understanding of TCP but I think I can have multiple remote addresses connected to the
same local IP:port address.

Anyway this seems to be where my problem exists because when I define the same 'bindaddress'
IP:Port tuple to each connectTCP call, I only seem to be able to connect to one remote server
from the client application.

To put this into more context I set up two servers, the first on 127.0.0.1:35000, the second on
192.168.1.2:36000. (The reason I'm not putting both connections on the same IP is that internal 
to the application I am tracking connections using the IP as the key in a dict, therefore I need
unique IP strings). Then I setup the client bindaddress to use say 127.0.0.1:37000. (This problem
does not seem to be related to the use of the 127... loopback address as I get the same result
when I set the client to use the externally visable 192... address).

If I don't specify the 'bindaddress' argument (Ie let the OS define the port etc) I can connect to
multiple servers. However this means I don't conform to my port range usage requirements.
I'm sure I'm missing something simple here.

Any helpful ideas would be greatly appreciated.

chris




More information about the Twisted-Python mailing list