小编jor*_*001的帖子

如何限制Twisted中的同时连接数

所以我建立了一个扭曲的服务器,我想知道限制同时连接数的最佳方法是什么?

让我的工厂回归没有最好的方法吗?当我这样做时,我抛出了很多例外,例如:

exceptions.AttributeError: 'NoneType' object has no attribute 'makeConnection'
Run Code Online (Sandbox Code Playgroud)

我想在某种程度上让客户只是坐在队列中,直到当前的连接数回落,但我不知道如何异步.

目前我正在使用我的工厂这样做:

class HandleClientFactory(Factory):

    def __init__(self):
            self.numConnections = 0 

    def buildProtocol(self, addr):
            #limit connection number here
            if self.numConnections >= Max_Clients:
                    logging.warning("Reached maximum Client connections")
                    return None

            return HandleClient(self)
Run Code Online (Sandbox Code Playgroud)

哪个有效,但断开连接而不是等待,并且还会抛出许多未处理的错误.

python asynchronous twisted python-2.7 twisted.internet

3
推荐指数
1
解决办法
1287
查看次数