1
私はconnector.connect()
に電話をかけて、ツイストクライアントからサーバーにメッセージを送信することがあります。しかし、クライアントは異なるポートで作られるでしょう。次のコードこのケースを実証している:ツイスト:ツイストクライアントによるメッセージをシングルポートで送信する方法は?
SERVER_HOST = 'localhost'
SERVER_PORT = '5000'
class EchoClient(protocol.Protocol):
def connectionMade(self):
self.transport.write("message")
self.transport.loseConnection()
class EchoFactory(protocol.ClientFactory):
def buildProtocol(self, addr):
print('Connected.')
return EchoClient()
def clientConnectionLost(self, connector, reason):
print('Lost connection. Reason:', reason)
connector.connect()
def main():
reactor.connectTCP(SERVER_HOST, SERVER_PORT, EchoFactory())
reactor.run()
そして、私のねじれたサーバーは、私を言う:
Packet received, client 127.0.0.1:41930, size: 7
Connection lost
Packet received, client 127.0.0.1:41931, size: 7
Connection lost
Packet received, client 127.0.0.1:41932, size: 7
Connection lost
Packet received, client 127.0.0.1:41933, size: 7
クライアントは異なるポートがある - 単一のポートでねじれたクライアントからメッセージを送信する方法41930、41931、などを?