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']
怎麼做呢?
好的謝謝你的幫助 –