client.py 文件源码

python
阅读 45 收藏 0 点赞 0 评论 0

项目:defuse_division 作者: lelandbatey 项目源码 文件源码
def zeroconf_info():
    """zeroconf_info returns a list of tuples of the information about other
    zeroconf services on the local network. It does this by creating a
    zeroconf.ServiceBrowser and spending 0.25 seconds querying the network for
    other services."""
    ret_info = []

    def on_change(zeroconf, service_type, name, state_change):
        if state_change is zeroconfig.ServiceStateChange.Added:
            info = zeroconf.get_service_info(service_type, name)
            if info:
                address = "{}".format(socket.inet_ntoa(info.address))
                props = str(info.properties.items())
                item = ServerInfo(str(info.server), address, info.port, props)
                ret_info.append(item)

    zc = zeroconfig.Zeroconf()
    browser = zeroconfig.ServiceBrowser(
        zc, "_defusedivision._tcp.local.", handlers=[on_change])
    sleep(1)
    concurrency.concurrent(lambda: zc.close())()
    return ret_info
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号