How to use the curio.socket.socket 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 povilasb / udptest / udptest / client.py View on Github external
def __init__(self, target: Tuple[str, int], packet_count: int,
                 timeout: int=3) -> None:
        self._target = target
        self._packet_count = packet_count
        self._timeout = timeout

        self.packets_received = 0

        self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
github povilasb / hole-punching / holepunch / peer.py View on Github external
def __init__(self, bind_port: int) -> None:
        self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self._sock.bind(('0.0.0.0', bind_port))
github guyingbo / shadowproxy / shadowproxy / proxies / udpbase.py View on Github external
async def sendto_from(bind_addr, data, addr):
        try:
            if bind_addr not in socks:
                sender = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
                sender.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
                sender.setsockopt(socket.SOL_IP, IP_TRANSPARENT, 1)
                sender.bind(bind_addr)
                socks[bind_addr] = sender
            sender = socks[bind_addr]
            async with sender:
                await sender.sendto(data, addr)
        except OSError as e:
            if verbose > 0:
                print(e, bind_addr)
github guyingbo / shadowproxy / shadowproxy / proxies / base / udpclient.py View on Github external
def __init__(self, ns=None):
        self.ns = ns
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        if "source_addr" in self.ns:
            self.sock.bind(self.ns["source_addr"])
        self._task = None
github dabeaz / curio / curio / channel.py View on Github external
def bind(self):
        self.sock = socket.socket(self.family, socket.SOCK_STREAM)
        self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
        self.sock.bind(self.address)
        self.sock.listen(5)
        self.address = self.sock.getsockname()
github guyingbo / shadowproxy / legency / shadowproxy_v0_2_5.py View on Github external
async def sendto_from(bind_addr, data, addr):
        try:
            if bind_addr not in socks:
                sender = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
                sender.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
                sender.setsockopt(socket.SOL_IP, IP_TRANSPARENT, 1)
                sender.bind(bind_addr)
                socks[bind_addr] = sender
            sender = socks[bind_addr]
            async with sender:
                await sender.sendto(data, addr)
        except OSError as e:
            if verbose > 0:
                print(e, bind_addr)
github povilasb / hole-punching / holepunch / peer.py View on Github external
def __init__(self, bind_port: int) -> None:
        self._bind_port = bind_port
        self._sock = socket.socket()
        self._sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self._sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
        self._sock.bind(('0.0.0.0', bind_port))
github guyingbo / shadowproxy / shadowproxy.py View on Github external
async def sendto_from(bind_addr, data, addr):
        try:
            if bind_addr not in socks:
                sender = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
                sender.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
                sender.setsockopt(socket.SOL_IP, IP_TRANSPARENT, 1)
                sender.bind(bind_addr)
                socks[bind_addr] = sender
            sender = socks[bind_addr]
            async with sender:
                await sender.sendto(data, addr)
        except OSError as e:
            if verbose > 0:
                print(e, bind_addr)
    return sendto_from
github guyingbo / shadowproxy / shadowproxy / proxies / ssudp.py View on Github external
async def sendto_from(bind_addr, data, addr):
        try:
            if bind_addr not in socks:
                sender = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
                sender.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
                sender.setsockopt(socket.SOL_IP, IP_TRANSPARENT, 1)
                sender.bind(bind_addr)
                socks[bind_addr] = sender
            sender = socks[bind_addr]
            async with sender:
                await sender.sendto(data, addr)
        except OSError as e:
            gvars.logger.debug(f"{bind_addr} {e}")