eculocate

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

commit b93061917d29f842c78607ceaed7e838e11647bc
parent 9bb4f025d45f3401772a87654b33e8d885ef8947
Author: Daniel Barlow <dan@telent.net>
Date:   Sun, 11 Jan 2026 15:09:34 +0000

send and receive udp

Diffstat:
Mshore.py | 42+++++++++++++++++++++++++++++-------------
1 file changed, 29 insertions(+), 13 deletions(-)

diff --git a/shore.py b/shore.py @@ -4,10 +4,11 @@ import termuxgui as tg import time import sys import socket - +import threading +import select peer_hostname = None -peer_socket = None +peer_thread = None started = False @@ -17,6 +18,27 @@ hosts = { "eculogical3.local" : None } +def recording_thread_main(): + sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + sock.connect((peer_hostname, 5000)) + sock.setblocking(0) + interval = 500 + while started: + print("sending subscribe") + b = bytes([interval >> 8, interval & 0xff, 0x54, 0x11, 0, 25] ) + sock.send(b) + timeout = time.time() + 60 + while started and time.time() < timeout: + ready = select.select([sock], [], [], timeout - time.time()) + if ready[0]: + data = sock.recv(4000) + print(f"got data {len(data)}" ) + 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) @@ -57,22 +79,16 @@ with tg.Connection() as c: else: start_button.settext("STOP" if started else "START") + def start_recording(start_or_stop): global started - global peer_socket if start_or_stop and peer_hostname != None: started = True - print("pretending to do udp things") - peer_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - peer_socket.connect((peer_hostname, 5000)) - interval = 500 - b = bytes([interval >> 8, interval & 0xff, 0x54, 0x11, 0, 25] ) - peer_socket.send(b) + print("starting record") + peer_thread = threading.Thread(target=recording_thread_main, daemon = True) + peer_thread.start() else: - print("pretending to close udp socket") - if peer_socket != None: - peer_socket.close() - peer_socket = None + print("stopping record") started = False instances = tg.LinearLayout(a)