我有一个 Twisted 套接字,我试图在多个端口上运行。以下代码以前对我有用,但那是大约 1 个月前,因为如果我没记错的话,我从那以后就没有接触过代码。现在,在我的 Twisted 程序中重新输入代码后,它不再工作了。
class Socket(Protocol):
table = Table()
def connectionMade(self):
#self.transport.write("""connected""")
self.factory.clients.append(self)
print "Clients are ", self.factory.clients
def connectionLost(self, reason):
self.factory.clients.remove(self)
def dataReceived(self, data):
#print "data is ", data
a = data.split(':')
if len(a) > 1:
command = a[0]
content = a[1]
if command == "Number_of_Players":
msg = table.numberOfPlayers
print msg
for c in self.factory.clients:
c.message(msg)
def message(self, message):
self.transport.write(message)
NUM_TABLES = 10
factories = [ ]
for i in range(0, NUM_TABLES):
print i
factory = Factory()
factory.protocol = Socket
factory.clients = []
factories.append(factory)
reactor.listenTCP(1025+i, factory)
#print "Blackjack server started"
reactor.run()
它通常会在我设置的范围内打印 Blackjack 服务器启动的次数,但现在不会。为了测试它是否循环,我开始打印 i,但它只打印了 0。由于某种原因,for 循环只循环了 1 次。
有什么建议么?谢谢!