Permalink
Browse files

Register ponyd as a bonjour service

  • Loading branch information...
1 parent 74419cb commit 4dedee22cb8892e26d559e12d8d103bf3b1305ef @jeanregisser jeanregisser committed Oct 14, 2012
Showing with 37 additions and 1 deletion.
  1. +27 −0 ponyd/bonjour.py
  2. +9 −0 ponyd/gateway.py
  3. +1 −1 setup.py
View
@@ -0,0 +1,27 @@
+import select
+import pybonjour
+import logging
+
+logger = logging.getLogger('bonjour')
+
+def register_service(name, regtype, port):
+ def register_callback(sdRef, flags, errorCode, name, regtype, domain):
+ if errorCode == pybonjour.kDNSServiceErr_NoError:
+ logger.debug('Registered bonjour service %s.%s', name, regtype)
+
+ service = pybonjour.DNSServiceRegister(name = name,
+ regtype = regtype,
+ port = port,
+ callBack = register_callback)
+
+ try:
+ try:
+ while True:
+ ready = select.select([service], [], [])
+ if service in ready[0]:
+ pybonjour.DNSServiceProcessResult(service)
+ except KeyboardInterrupt:
+ pass
+ finally:
+ service.close()
+
View
@@ -8,12 +8,15 @@
from ponyd.argbase import Arg
import os
+import thread
import json
import uuid
import argparse
+import bonjour
+
import logging
from ponyd.constants import DEFAULT_DEVTOOLS_PATH
@@ -213,6 +216,10 @@ class Gateway(PonydCommand):
default='127.0.0.1',
metavar='IFACE')
+ bonjour_name = Arg('-b', '--bonjour-name',
+ help='name of the bonjour service. [default: %(default)s]',
+ default='Pony Gateway')
+
def __call__(self):
if not os.path.exists(self.devtools_path):
print "Error: devtools directory %s does not exist. Use ponydownloader to download a compatible version of Chrome Developer Tools." % self.devtools_path
@@ -233,6 +240,8 @@ def __call__(self):
print "PonyGateway starting. Listening on %s:%s" % (self.listen_interface, self.listen_port)
+ thread.start_new_thread(bonjour.register_service, (self.bonjour_name, "_ponyd._tcp", self.listen_port))
+
application.listen(self.listen_port, self.listen_interface)
tornado.ioloop.IOLoop.instance().start()
View
@@ -24,7 +24,7 @@ def read(fname):
author_email='eng@squareup.com',
url='https://github.com/square/PonyDebugger',
license='Apache Licence 2.0',
- install_requires=['tornado'],
+ install_requires=['tornado', 'pybonjour'],
packages=['ponyd'],
include_package_data=True,
zip_safe=False,

0 comments on commit 4dedee2

Please sign in to comment.