Пример #1
0
 def mk_client(self, worker, call_uuid="test-uuid"):
     addr = worker.voice_server.getHost()
     client = FakeFreeSwitchProtocol(call_uuid)
     self._clients.append(client)
     factory = ClientFactory.forProtocol(lambda: client)
     yield reactor.connectTCP("127.0.0.1", addr.port, factory)
     yield client.connect_d
     returnValue(client)
Пример #2
0
 def _initClient(self, clientConnString):
     """
     Инициализация клиента
     :type clientConnString: str строка подключения для clientFromString
     :return : defer.Deferred с аргументом self.clientProtocol
     """
     clientEndpoint = clientFromString(self.reactor, clientConnString)
     saveProtocol = lambda p: save(self, 'clientProtocol', p)  # given protocol
     self.clientFactory = ClientFactory.forProtocol(lambda: AMP(locator=self.locator))
     return clientEndpoint.connect(self.clientFactory).addCallback(saveProtocol).addCallback(self.setClientProtocol)
Пример #3
0
 def _connectClient(self, d2):
     """
     Подключиться к серверу
     :param d2: defer.Deferred вызываемый при connectionLost
     :return: defer.Deferred с результатом подключения (инициализированный протокол ClientProtocolStub)
     """
     factory = ClientFactory.forProtocol(ClientProtocolStub)
     factory.onConnectionLost = d2
     return clientFromString(self.reactor, b"tcp:host=localhost:port={0}".format(self.serverPort.getHost().port)) \
         .connect(factory)
Пример #4
0
        def listening(port):
            msg("Listening on %r" % (port.getHost(),))
            endpoint = self.endpoints.client(reactor, port.getHost())

            client = endpoint.connect(
                ClientFactory.forProtocol(lambda: clientProtocol))
            def disconnect(proto):
                msg("About to disconnect %r" % (proto,))
                proto.transport.loseConnection()
            client.addCallback(disconnect)
            client.addErrback(lostConnectionDeferred.errback)
            return lostConnectionDeferred
Пример #5
0
        def listening(port):
            msg("Listening on %r" % (port.getHost(),))
            endpoint = self.endpoints.client(reactor, port.getHost())

            lostConnectionDeferred = Deferred()
            protocol = lambda: ClosingLaterProtocol(lostConnectionDeferred)
            client = endpoint.connect(ClientFactory.forProtocol(protocol))
            def write(proto):
                msg("About to write to %r" % (proto,))
                proto.transport.write(b'x')
            client.addCallbacks(write, lostConnectionDeferred.errback)

            def disconnected(proto):
                msg("%r disconnected" % (proto,))
                proto.transport.write(b"some bytes to get lost")
                proto.transport.writeSequence([b"some", b"more"])
                finished.append(True)

            lostConnectionDeferred.addCallback(disconnected)
            serverConnectionLostDeferred.addCallback(disconnected)
            return gatherResults([lostConnectionDeferred,
                                  serverConnectionLostDeferred])
Пример #6
0
 def setUp(self):
     self.client_factory = ClientFactory.forProtocol(DummyClientProtocol)
     self.server_factory = ServerFactory.forProtocol(DummyServerProtocol)
Пример #7
0
 def setUp(self):
     self.client_factory = ClientFactory.forProtocol(DummyClientProtocol)
     self.server_factory = ServerFactory.forProtocol(DummyServerProtocol)
Пример #8
0
def main(reactor):
    ep = UNIXClientEndpoint(reactor, '/var/run/postgresql/.s.PGSQL.5432')
    fact = ClientFactory.forProtocol(PostgresProtocol)
    proto = yield ep.connect(fact)
    # for i in range(5000):
    res = yield proto.runQuery('SELECT * from entries limit 5')
Пример #9
0
def main(reactor):
    ep = UNIXClientEndpoint(reactor, '/var/run/postgresql/.s.PGSQL.5432')
    fact = ClientFactory.forProtocol(PostgresProtocol)
    proto = yield ep.connect(fact)
    # for i in range(5000):
    res = yield proto.runQuery('SELECT * from entries limit 5')