示例#1
0
def uhej_worker_thread():
    """
    The worker thread used by uHej for service discovery
    """
    global discovery_list
    global sock
    while 1:
        try:
            data, addr = sock.recvfrom(1024)
            port = addr[1]
            addr = addr[0]
            frame = bytearray(data)
            try:
                f = uhej.decode_frame(frame)
                f["source"] = addr
                f["port"] = port
                types = ["UDP", "TCP", "mcast"]
                if uhej.ANNOUNCE == f["frame_type"]:
                    for s in f["services"]:
                        key = "{}:{}:{}".format(f["source"], s["port"],
                                                s["type"])
                        if key not in discovery_list:
                            if s["service_name"] == "opendps":
                                discovery_list[
                                    key] = True  # Keep track of which hosts we have seen
                                print("{}".format(f["source"]))
                                # print("{:>16}:{:<5d}  {:<8} {}".format(f["source"], s["port"], types[s["type"]], s["service_name"]))
            except uhej.IllegalFrameException as e:
                pass
        except socket.error as e:
            print('Exception', e)
示例#2
0
def uhej_worker_thread():
    global discovery_list
    global sock
    while 1:
        try:
            data, addr = sock.recvfrom(1024)
            port = addr[1]
            addr = addr[0]
            frame = bytearray(data)
            try:
                f = uhej.decode_frame(frame)
                f["source"] = addr
                f["port"] = port
                types = ["UDP", "TCP", "mcast"]
                if uhej.ANNOUNCE == f["frame_type"]:
                    for s in f["services"]:
                        key = "%s:%s:%s" % (f["source"], s["port"], s["type"])
                        if not key in discovery_list:
                            if s["service_name"] == "opendps":
                                discovery_list[
                                    key] = True  # Keep track of which hosts we have seen
                                print("%s" % (f["source"]))


#                            print("%16s:%-5d  %-8s %s" % (f["source"], s["port"], types[s["type"]], s["service_name"]))
            except uhej.IllegalFrameException as e:
                pass
        except socket.error as e:
            print('Exception'), e