Example #1
0
def server_loop_runner(loop, sock, handler, protocol_factory=None):
    return loop.run_until_complete(
        ThriftAsyncServerFactory(
            handler,
            port=None,
            loop=loop,
            sock=sock,
            protocol_factory=protocol_factory,
        ), )
Example #2
0
 def setUp(self):
     global loop
     self.host = '127.0.0.1'
     self.handler = TestHandler()
     self.server = yield from ThriftAsyncServerFactory(
         self.handler,
         interface=self.host,
         port=0,
         loop=loop,
     )
     self.port = self.server.sockets[0].getsockname()[1]
     self.transport, self.protocol = yield from loop.create_connection(
         ThriftClientProtocolFactory(ThriftTest.Client),
         host=self.host,
         port=self.port,
     )
     self.client = self.protocol.client
Example #3
0
def main():
    parser = ArgumentParser()
    parser.add_argument('--port',
                        default=1234,
                        type=int,
                        help='Port to run on')
    options = parser.parse_args()
    loop = asyncio.get_event_loop()
    handler = LoadHandler()
    server = loop.run_until_complete(
        ThriftAsyncServerFactory(handler, port=options.port, loop=loop))
    print("Running Asyncio server on port {}".format(options.port))

    try:
        loop.run_forever()
    except KeyboardInterrupt:
        print("Caught SIGINT, exiting")
    finally:
        server.close()
        loop.close()
Example #4
0
    def getStruct(self, key):
        print('getStruct(%d)' % (key))
        return self.log[key]

    def zip(self):
        print('zip')


if __name__ == '__main__':
    # 1. Which loop we want to setup the server for?
    loop = asyncio.get_event_loop()
    handler = CalculatorHandler()
    # 2. Setup processors, event handlers and create the AsyncIO server.
    print('Creating the server...')
    server = loop.run_until_complete(
        ThriftAsyncServerFactory(handler, port=8848, loop=loop), )

    # Alternatively, if you'd like to asynchronously initialize multiple
    # servers at once, see the docstring of ThriftAsyncServerFactory.

    # 3. Explicitly runn the loop, which gives us flexibility to add more
    # servers, coroutines and other relevant setup.
    print('Running the server...')
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        print("Server caught SIGINT, exiting.")
    finally:
        server.close()
        loop.close()

if __name__ == "__main__":
    loop = asyncio.get_event_loop()

    certfile = "/root/ssl-stuff/server.pem"
    context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
    context.verify_mode = ssl.CERT_REQUIRED
    context.load_cert_chain(certfile=certfile, keyfile=certfile)
    context.load_verify_locations(cafile="/root/ssl-stuff/rootca.pem")

    handler = TestServiceHandler()
    server = loop.run_until_complete(
        ThriftAsyncServerFactory(
            handler,
            loop=loop,
            port=29292,
            ssl=context,
            event_handler=TestTServerEventHandler(),
        ))

    print("Starting server...")
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        server.close()
        loop.close()
        sys.exit(1)

    sys.exit(0)
Example #6
0
def server_loop_runner(loop, sock):
    asyncio.set_event_loop(loop)
    handler = DummyCalcHandler()
    loop.run_until_complete(
        ThriftAsyncServerFactory(handler, port=None, loop=loop, sock=sock),
    )