Пример #1
0
def main(ip):
    """Create a multicast socket, send a message, check it comes back"""
    port = PORT
    sock = mcastsocket.create_socket( (ip,port), loop=False )
    mcastsocket.join_group( sock, GROUP )
    try:
        payload = query % locals()
        while True:
            sock.sendto( payload, 0, (GROUP,PORT))
            #print 'Waiting for responses'
            rs,wr,xs = select.select( [sock],[],[], 20.0 )
            if rs:
                data, addr = sock.recvfrom( 2000 )
                handle( sock, data, addr )
        return 1
    finally:
        mcastsocket.leave_group( sock, GROUP )
Пример #2
0
    def __init__(self, bindaddress=None):
        """Creates an instance of the Bonjour class, establishing
        multicast communications, listening and reaping threads."""
        globals()['_GLOBAL_DONE'] = 0
        if bindaddress is None:
            self.intf = socket.gethostbyname(socket.gethostname())
            bindaddress = self.intf
        else:
            self.intf = bindaddress
        self.socket = mcastsocket.create_socket( (bindaddress, dns._MDNS_PORT) )
        mcastsocket.join_group( self.socket, dns._MDNS_ADDR )

        self.listeners = []
        self.browsers = []
        self.services = {}

        self.cache = dns.DNSCache()

        self.condition = threading.Condition()

        self.engine = Engine(self)
        self.listener = Listener(self)
        self.reaper = Reaper(self)