我在玩 Twisted 并创建了一个简单的“服务器”。
我想让服务器监听多个端口(1025-65535)而不是单个端口。
我怎样才能做到这一点 ?
我的代码:
from twisted.internet.protocol import Protocol,ServerFactory
from twisted.internet import reactor
class QuickDisconnectProtocol(Protocol):
def connectionMade(self):
print "Connection from : ", self.transport.getPeer()
self.transport.loseConnection() # terminate connection
f = ServerFactory()
f.protocol = QuickDisconnectProtocol
reactor.listenTCP(6666,f)
reactor.run()
已经尝试过这个:
for i in range (0, 64510):
reactor.listenTCP(1025+i,f)
reactor.run()
但是收到一个错误:
Traceback (most recent call last):
File "Server.py", line 14, in <module>
File "/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.py", line 436, in listenTCP
File "/usr/lib/python2.7/dist-packages/twisted/internet/tcp.py", line 641, in startListening
twisted.internet.error.CannotListenError: Couldn't listen on any:2044: [Errno 24] Too many open files.