Grissess 7 жил өмнө
parent
commit
c92f688034
1 өөрчлөгдсөн 19 нэмэгдсэн , 12 устгасан
  1. 19 12
      broadcast.py

+ 19 - 12
broadcast.py

@@ -38,6 +38,7 @@ parser.add_option('-v', '--verbose', dest='verbose', action='store_true', help='
 parser.add_option('-W', '--wait-time', dest='wait_time', type='float', help='How long to wait between pings for clients to initially respond (delays all broadcasts)')
 parser.add_option('--tries', dest='tries', type='int', help='Number of ping packets to send')
 parser.add_option('-B', '--bind-addr', dest='bind_addr', help='The IP address (or IP:port) to bind to (influences the network to send to)')
+parser.add_option('--to', dest='to', action='append', help='IP:port pairs to send to (skips discovery)')
 parser.add_option('--port', dest='ports', action='append', type='int', help='Add a port to find clients on')
 parser.add_option('--clear-ports', dest='ports', action='store_const', const=[], help='Clear ports previously specified (including the default)')
 parser.add_option('--repeat', dest='repeat', action='store_true', help='Repeat the file playlist indefinitely')
@@ -51,7 +52,7 @@ parser.add_option('--pg-fullscreen', dest='fullscreen', action='store_true', hel
 parser.add_option('--pg-width', dest='pg_width', type='int', help='Width of the pygame window')
 parser.add_option('--pg-height', dest='pg_height', type='int', help='Width of the pygame window')
 parser.add_option('--help-routes', dest='help_routes', action='store_true', help='Show help about routing directives')
-parser.set_defaults(routes=['T:DRUM=!perc,0'], random=0.0, rand_low=80, rand_high=2000, live=None, factor=1.0, duration=0.25, volume=1.0, wait_time=0.1, tries=5, play=[], transpose=0, seek=0.0, bind_addr='', ports=[13676, 13677],  pg_width = 0, pg_height = 0, number=-1, pcmlead=0.1)
+parser.set_defaults(routes=['T:DRUM=!perc,0'], random=0.0, rand_low=80, rand_high=2000, live=None, factor=1.0, duration=0.25, volume=1.0, wait_time=0.1, tries=5, play=[], transpose=0, seek=0.0, bind_addr='', to=[], ports=[13676, 13677],  pg_width = 0, pg_height = 0, number=-1, pcmlead=0.1)
 options, args = parser.parse_args()
 
 if options.help_routes:
@@ -165,17 +166,23 @@ uid_groups = {}
 type_groups = {}
 ports = {}
 
-if not options.dry:
-    s.settimeout(options.wait_time)
-    for PORT in options.ports:
-        for num in xrange(options.tries):
-            s.sendto(str(Packet(CMD.PING)), ('255.255.255.255', PORT))
-            try:
-                while True:
-                    data, src = s.recvfrom(4096)
-                    clients.add(src)
-            except socket.timeout:
-                pass
+s.settimeout(options.wait_time)
+
+if options.to:
+    for dst in options.to:
+        host, _, port = dst.partition(':')
+        clients.add((host, int(port)))
+else:
+    if not options.dry:
+        for PORT in options.ports:
+            for num in xrange(options.tries):
+                s.sendto(str(Packet(CMD.PING)), ('255.255.255.255', PORT))
+                try:
+                    while True:
+                        data, src = s.recvfrom(4096)
+                        clients.add(src)
+                except socket.timeout:
+                    pass
 
 print len(clients), 'detected clients'