Multiple, Simultaneous Factories and Protocols in Twisted: Same Service, Different Ports
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 开发者_JAVA技巧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)?
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.
精彩评论