views:

157

answers:

1

Greetings, Forum.

I'm working on a program in Python that uses Twisted to manage networking. The basis of this program is a TCP service that is to listen for connections on multiple ports. However, instead of using one Twisted factory to handle a protocol object for each port, I am trying to use a separate factory for each port. The reason for this is to force a separation among the groups of clients connecting to the different ports.

Unfortunately, it appears that this architecture isn't quite working: clients that connect to one port appear to be available among all the factories (e.g., the protocol class used by each factory includes a 'self.factory.clients.append (self)' statement...instead of adding a given client to just the factory for a particular port, the client is added to all factories), and whenever I shutdown service on one port the listeners on all ports also stop.

I've been working with Twisted for a short while, and fear I simply don't fully understand how its factory classes are managed.

My question is: is it simply not possible to have multiple, simultaneous instances of the same factory and same protocol in use across different ports (without these instances stepping on each other's toes)?

+2  A: 

You can definitely do what you want -- it's hard to tell what you're doing wrong without seeing your code, but I'd bet you have clients = [] in your factory class instead of

self.clients = []

in your factory class's __init__ method.

Alex Martelli
Wow--I would not want to bet against you, ever!How utterly ridiculous of me to not catch that. The whole issue disappeared as soon as I moved initialization of the 'clients' list into my factory's __init__ method.Thanks very much for your speedy reply!!
RichardCroasher
and not to mention 'you probably need to do this in your `__init__`' Now that's class - no pun intended.
jeffjose