def test_ping_pong(self): server = MelkwegServerProtocol() client = MelkwegClientProtocol() server_fake_transport = FakeTransport() client_fake_transport = FakeTransport() server.transport = server_fake_transport client.transport = client_fake_transport client.connectionMade() self.assertEqual(len(client_fake_transport.buffer), 1) server.stringReceived(client_fake_transport.buffer[-1]) self.assertEqual(server.status, ProtocolStatus.RUNNING) client.stringReceived(server_fake_transport.buffer[-1]) self.assertEqual(client.status, ProtocolStatus.RUNNING) packet1 = PacketFactory.create_data_packet(1234, "hello world") client.write(packet1)
def clientConnectionLost(self, connector, reason): logging.error("connection lost: %s" % reason) MelkwegClientProtocolFactory.outgoing = MelkwegClientProtocol() protocol.ReconnectingClientFactory.clientConnectionLost( self, connector, reason)
def buildProtocol(self, addr): self.outgoing = MelkwegClientProtocol() return self.outgoing
def buildProtocol(self, addr): if self.outgoing == None: MelkwegClientProtocolFactory.outgoing = MelkwegClientProtocol() return self.outgoing
def __init__(self): MelkwegClientProtocolFactory.outgoing = MelkwegClientProtocol()