Twisted 中的多个同时工厂和协议:相同的服务,不同的端口
你好,论坛。
我正在开发一个 Python 程序,它使用 Twisted 来管理网络。该程序的基础是一个 TCP 服务,用于侦听多个端口上的连接。然而,我尝试为每个端口使用一个单独的工厂,而不是使用一个 Twisted 工厂来处理每个端口的协议对象。这样做的原因是强制将连接到不同端口的客户端组分开。
不幸的是,这种架构似乎不太有效:连接到一个端口的客户端似乎在所有工厂中都可用(例如,每个工厂使用的协议类包括一个“self.factory.clients.append(self)”) '声明...而不是将给定客户端添加到特定端口的工厂,而是将客户端添加到所有工厂),并且每当我关闭一个端口上的服务时,所有端口上的侦听器也会停止。
我使用 Twisted 已经有一段时间了,担心我根本不完全理解它的工厂类是如何管理的。
我的问题是:是否根本不可能在不同端口上使用同一工厂和同一协议的多个同时实例(这些实例不会互相干扰)?
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)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你绝对可以做你想做的事——如果不看代码,很难判断你做错了什么,但我敢打赌你的工厂类中有
clients = []
而不是你的 工厂类中有
clients = []
工厂类的 __init__ 方法。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 ofin your factory class's
__init__
method.