Make StreamReader search for a free port
This commit is contained in:
parent
ed53316f4f
commit
6f3c1ac740
@ -20,6 +20,9 @@ class Service(object):
|
||||
def get_port(self):
|
||||
return self._port
|
||||
|
||||
def set_port(self, port):
|
||||
self._port = port
|
||||
|
||||
def is_multicast(self):
|
||||
return self._multicast
|
||||
|
||||
|
@ -29,8 +29,18 @@ class StreamReader:
|
||||
server.start()
|
||||
|
||||
def _setup_unicast(self):
|
||||
p2p_server = GlibXMLRPCServer(("", self._service.get_port()))
|
||||
started = False
|
||||
tries = 10
|
||||
port = self._service.get_port()
|
||||
while not started and tries > 0:
|
||||
try:
|
||||
p2p_server = GlibXMLRPCServer(("", port))
|
||||
p2p_server.register_instance(StreamReaderRequestHandler(self))
|
||||
started = True
|
||||
except:
|
||||
port = port + 1
|
||||
tries = tries - 1
|
||||
self._service.set_port(port)
|
||||
|
||||
def _recv_multicast(self, msg):
|
||||
[ nick_name, data ] = msg['data'].split(" |**| ", 2)
|
||||
|
@ -31,7 +31,7 @@ class PresenceDiscovery(object):
|
||||
self.server.ResolveService(int(interface), int(protocol), name, stype, domain, avahi.PROTO_UNSPEC, dbus.UInt32(0), reply_handler=reply_handler, error_handler=error_handler)
|
||||
|
||||
def new_service(self, interface, protocol, name, stype, domain, flags):
|
||||
print "Found service '%s' (%d) of type '%s' in domain '%s' on %i.%i." % (name, flags, stype, domain, interface, protocol)
|
||||
# print "Found service '%s' (%d) of type '%s' in domain '%s' on %i.%i." % (name, flags, stype, domain, interface, protocol)
|
||||
for listener in self._service_listeners:
|
||||
listener(ACTION_SERVICE_NEW, interface, protocol, name, stype, domain, flags)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user