Exemplo n.º 1
0
async def serve(handler, host="", port=0):
    if not host:
        host = util.local_address()
    logger.info("Starting TCP server at %s:%i", host, port)
    server = await anyio.create_tcp_server(port, host)
    async with anyio.create_task_group() as group:
        async with TCPServer(handler, server, group) as server:
            await server.start()
            yield
    logger.info("TCP server is closed")
Exemplo n.º 2
0
    def prepare_station_location(self):
        host = util.local_address()
        port = self.transport.local_address()[1]

        location = StationLocation()
        location.local = StationAddress(host, port)
        location.pid = self.get_principal_id()
        location.cid = random.randint(0, 0xFFFFFFFF)
        location.rvcid = self.generate_session_id()
        location.type = 0
        return location
Exemplo n.º 3
0
async def bind(host="", port=0):
    if not host:
        host = util.local_address()

    logger.debug("Creating UDP socket at %s:%i", host, port)

    sock = await anyio.create_udp_socket(interface=host, port=port)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, True)

    async with UDPSocket(sock) as sock:
        yield sock

    logger.debug("UDP socket is closed")
Exemplo n.º 4
0
async def serve(handler, host="", port=0, context=None):
	if not host:
		host = util.local_address()
	logger.info("Starting TLS server at %s:%i", host, port)
	if context is None:
		server = await anyio.create_tcp_server(port, host)
	else:
		server = await anyio.create_tcp_server(
			port, host, context.get(True), tls_standard_compatible=False
		)
	async with anyio.create_task_group() as group:
		async with TLSServer(handler, server, group) as server:
			await server.start()
			yield
	logger.info("TLS server is closed")
Exemplo n.º 5
0
 def local_address(self):
     host, port = self.s.getsockname()
     if host == "0.0.0.0":
         return util.local_address(), port
     return host, port
Exemplo n.º 6
0
def test_broadcast_address():
    addr = util.local_address()
    util.ip_to_hex(addr)  # Raises exception if ip address is invalid