Example #1
0
async def multicast(
    loop: asyncio.AbstractEventLoop,
    services: typing.List[str],
    address: str = "224.0.0.251",
    port: int = 5353,
    timeout: int = 4,
    end_condition: typing.Optional[typing.Callable[[Response], bool]] = None,
) -> typing.Dict[IPv4Address, Response]:
    """Send multicast request for services."""
    protocol = MulticastDnsSdClientProtocol(
        loop, services, address, port, end_condition
    )

    # Socket listening on 5353 from anywhere
    await protocol.add_socket(net.mcast_socket(None, 5353))

    # One socket per local IP address
    for addr in net.get_private_addresses():
        try:
            await protocol.add_socket(net.mcast_socket(str(addr)))
        except Exception:  # pylint: disable=broad-except
            _LOGGER.exception(f"failed to add listener for {addr}")

    return await typing.cast(MulticastDnsSdClientProtocol, protocol).get_response(
        timeout
    )
Example #2
0
async def multicast(
    loop: asyncio.AbstractEventLoop,
    services: List[str],
    address: str = "224.0.0.251",
    port: int = 5353,
    timeout: int = 4,
) -> Dict[IPv4Address, Response]:
    """Send multicast request for services."""
    protocol = MulticastDnsSdClientProtocol(loop, services, address, port)

    # Socket listening on 5353 from anywhere
    await protocol.add_socket(net.mcast_socket(None, 5353))

    # One socket per local IP address
    for addr in net.get_private_addresses():
        try:
            await protocol.add_socket(net.mcast_socket(str(addr)))
        except Exception:
            _LOGGER.exception(f"failed to add listener for {addr}")

    return await cast(MulticastDnsSdClientProtocol, protocol).get_response(timeout)