def testPortforward(self): serverProtocol = wire.Echo() realServerFactory = protocol.ServerFactory() realServerFactory.protocol = lambda: serverProtocol realServerPort = reactor.listenTCP(0, realServerFactory, interface='127.0.0.1') proxyServerFactory = portforward.ProxyFactory('127.0.0.1', realServerPort.getHost().port) proxyServerPort = reactor.listenTCP(0, proxyServerFactory, interface='127.0.0.1') nBytes = 1000 received = [] clientProtocol = protocol.Protocol() clientProtocol.dataReceived = received.extend clientProtocol.connectionMade = lambda: clientProtocol.transport.write('x' * nBytes) clientFactory = protocol.ClientFactory() clientFactory.protocol = lambda: clientProtocol reactor.connectTCP('127.0.0.1', proxyServerPort.getHost().port, clientFactory) c = 0 while len(received) < nBytes and c < 100: reactor.iterate(0.01) c += 1 self.assertEquals(''.join(received), 'x' * nBytes) clientProtocol.transport.loseConnection() serverProtocol.transport.loseConnection() return defer.gatherResults([ defer.maybeDeferred(realServerPort.stopListening), defer.maybeDeferred(proxyServerPort.stopListening)])
def testEcho(self): t = StringIOWithoutClosing() a = wire.Echo() a.makeConnection(protocol.FileWrapper(t)) a.dataReceived("hello") a.dataReceived("world") a.dataReceived("how") a.dataReceived("are") a.dataReceived("you") self.failUnlessEqual(t.getvalue(), "helloworldhowareyou")
def test_echo(self): """ Test wire.Echo protocol: send some data and check it send it back. """ t = proto_helpers.StringTransport() a = wire.Echo() a.makeConnection(t) a.dataReceived("hello") a.dataReceived("world") a.dataReceived("how") a.dataReceived("are") a.dataReceived("you") self.assertEquals(t.value(), "helloworldhowareyou")
def testEcho(self): """ Test wire.Echo protocol: send some data and check it send it back. """ t = StringIOWithoutClosing() a = wire.Echo() a.makeConnection(protocol.FileWrapper(t)) a.dataReceived("hello") a.dataReceived("world") a.dataReceived("how") a.dataReceived("are") a.dataReceived("you") self.failUnlessEqual(t.getvalue(), "helloworldhowareyou")
def setUp(self): self.serverProtocol = wire.Echo() self.clientProtocol = protocol.Protocol() self.openPorts = []