1
我想进入我的协议,并在我厂的值相同所以我做了这个代码测试:的Python:扭曲的服务器和值
import time
from multiprocessing import Process
from twisted.internet import reactor, protocol
class MyServer(protocol.Protocol):
def connectionMade(self):
self.factory.clients.append("client")
print self.factory.clients
class MyServerFactory(protocol.Factory):
def __init__(self):
self.protocol = MyServer
self.clients = []
def printClient(self):
print self.clients
if __name__ == '__main__':
factory = MyServerFactory()
reactor.listenTCP(4433, factory)
processTwisted = Process(target=reactor.run)
processTwisted.start()
time.sleep(10)
factory.printClient()
在睡眠我连接客户机到服务器。 这是控制台的日志:
['client']
[]
而且我预计:
['client']
['client']
怎么做呢?
好的谢谢你的帮助 –