How to use the curio.open_connection function in curio

To help you get started, we’ve selected a few curio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dabeaz / curio / examples / conn.py View on Github external
async def main():
    sock = await curio.open_connection(
        'www.python.org', 443, ssl=True, server_hostname='www.python.org')
    async with sock:
        await sock.sendall(b'GET / HTTP/1.0\r\nHost: www.python.org\r\n\r\n')
        chunks = []
        while True:
            chunk = await sock.recv(10000)
            if not chunk:
                break
            chunks.append(chunk)

    response = b''.join(chunks)
    print(response.decode('latin-1'))
github allenling / magne / magne / coro_consumer / dumy_redis.py View on Github external
async def connect(self):
        self.sock = await curio.open_connection(self.host, self.port)
        return
github nokia / moler / examples / layer_1 / curio / network_down_detector.py View on Github external
async def tcp_connection(address):
    """Async generator reading from tcp network transport layer"""
    logger = logging.getLogger('curio.tcp-connection')
    logger.debug('... connecting to tcp://{}:{}'.format(*address))
    host, port = address
    sock = await curio.open_connection(host, port)
    async with sock:
        while True:
            data = await sock.recv(128)
            if data:
                logger.debug('<<< {!r}'.format(data))
                yield data
            else:
                break
github guyingbo / shadowproxy / shadowproxy / utils.py View on Github external
async def open_connection(host, port, **kwargs):
    for i in range(2, -1, -1):
        try:
            return await curio.open_connection(host, port, **kwargs)
        except socket.gaierror:
            if i == 0:
                gvars.logger.debug(f"dns query failed: {host}")
                raise
github allenling / magne / magne / helper.py View on Github external
async def connect(self):
        self.sock = await curio.open_connection(self.host, self.port)
        self.logger.debug('open amqp connection')
        # send amqp header frame
        await self.send_amqp_procotol_header()
        self.logger.debug('send amqp header')
        # got start
        await self.assert_recv_method(pika.spec.Connection.Start)
        self.logger.debug('get amqp connection.Start')
        # send start ok back
        await self.send_start_ok()
        self.logger.debug('send amqp connection.StartOk')
        # got tune
        await self.assert_recv_method(pika.spec.Connection.Tune)
        self.logger.debug('get amqp connection.Tune')
        # send tune ok
        await self.send_tune_ok()
        self.logger.debug('send amqp connection.TuneOk')
github allenling / magne / magne / process_worker / connection.py View on Github external
async def connect(self):
        self.sock = await curio.open_connection(self.host, self.port)
        self.logger.debug('open amqp connection')
        # send amqp header frame
        await self.send_amqp_procotol_header()
        self.logger.debug('send amqp header')
        # got start
        await self.assert_recv_method(pika.spec.Connection.Start)
        self.logger.debug('get amqp connection.Start')
        # send start ok back
        await self.send_start_ok()
        self.logger.debug('send amqp connection.StartOk')
        # got tune
        await self.assert_recv_method(pika.spec.Connection.Tune)
        self.logger.debug('get amqp connection.Tune')
        # send tune ok
        await self.send_tune_ok()
        self.logger.debug('send amqp connection.TuneOk')
github guyingbo / shadowproxy / legency / shadowproxy_v0_2_5.py View on Github external
async def connect(self):
        return await curio.open_connection(*self.raddr)