Factory 和 ServerFactory/ClientFactory 有什么区别?

What's the difference between Factory and ServerFactory/ClientFactory?

我目前正在阅读一本关于 Twisted 的书,代码示例似乎任意使用了 protocol.Factoryprotocol.ServerFactory/ClientFactory。每个选项有什么区别以及何时应该使用?

这是一个使用 protocol.ServerFactory 的例子:

class HTTPEchoFactory(protocol.ServerFactory):
    def buildProtocol(self, addr):
        return HTTPEchoProtocol()

然而,他们在这里使用 protocol.Factory:

class RshFactory(Factory):

    def __init__(self):
        self.connected_clients = {}

    def buildProtocol(self, addr):
        return RshServer(self, addr)

ClientFactoryServerFactory大多是历史事故,最终应该被删除。如果你正在使用 endpoints(你应该是,任何在过去 3 年里用 twisted 编写的代码 应该 是)你应该只使用 Factory 并忽略他们。