Exemplo n.º 1
0
 def broadcast():
     broadcast_service = discovery.connectBonjour(broadcast_protocol,
                                                  registry,
                                                  port,
                                                  service_name,
                                                  )
     broadcast_service.setName('broadcast')
     broadcast_service.setServiceParent(s)
Exemplo n.º 2
0
import sys

from twisted.internet import reactor, task, defer
from twisted.python import log

from txbonjour import discovery, tap

if __name__ == "__main__":
    log.startLogging(sys.stdout)
    proto = tap.LoggingProtocol()

    # testing with services
    dservice = discovery.listenBonjour(proto, '_nodes._udp',)
    bservice = discovery.connectBonjour(proto,
                                       regtype='_nodes._udp',
                                       port=9994,
                                       name='ExampleUDPService',
                                       )
    reactor.callWhenRunning(dservice.startService)
    reactor.callWhenRunning(bservice.startService)
    d = task.deferLater(reactor, 5, bservice.stopService)

    def exit(service):
        rm(service)
        log.msg('broadcast service stopped, exiting now')
        reactor.stop()
        
    rm = proto.removeService
    proto.removeService = exit

    reactor.run()