eculocate

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit fe0d3dc2fe8d276d148db86631f136e9f82c25d4
parent 112499d237637b60c71e48528bf8a5f4a8a09646
Author: Daniel Barlow <dan@telent.net>
Date:   Sun, 11 Jan 2026 23:33:19 +0000

add dns-sd

Diffstat:
Mandroid-termux-client/eculocate.py | 86+++++++++++++++++++++++++++++++++++++++++++++++++------------------------------
1 file changed, 53 insertions(+), 33 deletions(-)

diff --git a/android-termux-client/eculocate.py b/android-termux-client/eculocate.py @@ -9,6 +9,7 @@ import select import datetime from pathlib import Path import os +from zeroconf import ServiceBrowser, ServiceListener, Zeroconf peer_hostname = None peer_thread = None @@ -16,11 +17,31 @@ bytes_recorded = 0 started = False -hosts = { - "eculocate.local" : None, - "eculocate2.local" : None, - "eculocate3.local" : None -} + +hosts = {} +host_addresses = {} + +class ZListener(ServiceListener): + def __init__(self, activity, parent_widget): + self.activity = activity + self.parent_widget = parent_widget + + def update_service(self, zc: Zeroconf, type_: str, name: str) -> None: + print(f"Service {name} updated") + + def remove_service(self, zc: Zeroconf, type_: str, name: str) -> None: + hosts[name] = 0 + print(f"Service {name} removed") + + def add_service(self, zc: Zeroconf, type_: str, name: str) -> None: + info = zc.get_service_info(type_, name) + print(f"Service {name} added, service info: {info}") + hosts[name] = None + host_addresses[name] = (socket.inet_ntoa(info.addresses[0]), info.port) + + +zeroconf = Zeroconf() + def output_pathname(): root = Path(os.getenv("HOME")) @@ -31,7 +52,10 @@ def output_pathname(): def recording_thread_main(): sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - sock.connect((peer_hostname, 5000)) + addr = host_addresses[peer_hostname] + print(peer_hostname) + print(addr) + sock.connect(addr) sock.setblocking(0) interval = 500 global bytes_recorded @@ -50,33 +74,26 @@ def recording_thread_main(): bytes_recorded = bytes_recorded + len(data) outf.write(data) outf.flush() - sock.close() print("recording thread terminated") - - - - # Intercept the back button. Instead of finishing the Activity, it now sends an event instead - # a.interceptbackbutton(True) - # Also possible: a = tg.Activity(c, intercept=True) +def add_host(activity, name, parent): + selected = (peer_hostname == name) + if selected: + label = f"* {name}" + else: + label = name + button = tg.Button(activity, label, parent) + button.setlinearlayoutparams(0) + button.setheight(tg.View.WRAP_CONTENT) + hosts[name] = button with tg.Connection() as c: # create a new Activity. By default, a new Task as created. a = tg.Activity(c) - # you can find the Task under a.t - def add_host(activity, name, parent): - selected = (peer_hostname == name) - if selected: - label = f"* {name}" - else: - label = name - button = tg.Button(activity, label, parent) - button.setlinearlayoutparams(0) - button.setheight(tg.View.WRAP_CONTENT) - hosts[name] = button + # you can find the Task under a.t def choose_hostname(hostname): global peer_hostname @@ -109,19 +126,17 @@ with tg.Connection() as c: print("stopping record") started = False - instances = tg.LinearLayout(a) - - add_host(a, "eculocate.local", instances) - add_host(a, "eculocate2.local", instances) - add_host(a, "eculocate3.local", instances) + vertical = tg.LinearLayout(a) + instances = tg.LinearLayout(a, vertical) + browser = ServiceBrowser(zeroconf, "_keihin._udp.local.", ZListener(a, instances)) - tg.Space(a, instances) + tg.Space(a, vertical) - status = tg.TextView(a, "initializing", instances) + status = tg.TextView(a, "initializing", vertical) - tg.Space(a, instances) + tg.Space(a, vertical) - buttons = tg.LinearLayout(a, instances, False) + buttons = tg.LinearLayout(a, vertical, False) start_button = tg.Button(a, "(start)", buttons) start_button.setlinearlayoutparams(0) @@ -135,6 +150,11 @@ with tg.Connection() as c: label = f"recorded {bytes_recorded} bytes" if started else "not recording" status.settext(label) time.sleep(1) + for host, button in hosts.items(): + if button == 0: + button.delete() + elif button == None: + add_host(a, host, instances) threading.Thread(target = update_byte_counter, daemon = True).start()