Skip to content

Add mDNS/Bonjour discovery for remote apps (no hard-coded ports)#96

Merged
dccote merged 2 commits into
mainfrom
feature/remote-network-discovery
Jul 7, 2026
Merged

Add mDNS/Bonjour discovery for remote apps (no hard-coded ports)#96
dccote merged 2 commits into
mainfrom
feature/remote-network-discovery

Conversation

@dccote

@dccote dccote commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary

RemoteControllable apps can now publish themselves on the local network and be
found by name, so clients no longer need a hard-coded host/port. Built on the
existing XML-RPC remote layer; the transport is unchanged.

What's new

ServerRemoteControllable.advertise_remote(port=0, host="0.0.0.0", service_type="_mytk._tcp.local.", addr=None)
starts the remote server on an OS-picked free port and announces it over mDNS.
app_name becomes the service instance name and is copied into the TXT record.
stop_remote() now also withdraws the announcement.

Clientmytk.discover(app_name=None, service_type="_mytk._tcp.local.", timeout=3.0)
browses for an advertised server and returns a proxy through the existing
connect(), so RemoteAppMismatch verification still applies. app_name
filters by the advertised identity.

CLImytk-remote --discover locates the server over mDNS instead of using
--host/--port; --app-name selects which app, --service-type/--timeout
tune the browse. Explicit --host/--port behavior is unchanged.

Usage

app.advertise_remote()                 # free port + mDNS announcement
far = mytk.discover(app_name="Microscope")
far.turn_on()
mytk-remote --discover --list
mytk-remote --discover --app-name Microscope "status()"

Packaging

New optional extra mytk[remote] (pulls in zeroconf). advertise_remote()
installs it on demand via ModulesManager (Tk context); discover() imports it
directly and raises a clear ImportError if missing.

Design notes

  • Service type describes the application protocol (_mytk._tcp), not the
    transport, per DNS-SD; multiple apps share it and are told apart by
    instance name / app_name.
  • Default host="0.0.0.0" on advertise_remote() makes the service reachable
    from other machines (mDNS is a LAN feature); pass 127.0.0.1 to keep it
    same-machine only. start_remote() still defaults to localhost.

Tests

mytk/tests/testRemoteDiscovery.py covers discover() browsing, app_name
filtering, timeout, and the missing-zeroconf ImportError, plus the CLI
--discover wiring. Hermetic via a fake zeroconf module — no multicast, no
sockets, no Tk window.

Compatibility

Backward compatible: no changes to existing signatures/defaults of
start_remote, connect, or the CLI's --host/--port path. zeroconf is
only needed when discovery is used.

🤖 Generated with Claude Code

dccote and others added 2 commits July 7, 2026 12:43
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
List every myTk app advertised on the LAN (name + address) without
connecting to any, complementing --discover which targets one.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dccote
dccote force-pushed the feature/remote-network-discovery branch from 05ee861 to eb60903 Compare July 7, 2026 16:43
@dccote
dccote merged commit 3f8805c into main Jul 7, 2026
11 checks passed
@dccote
dccote deleted the feature/remote-network-discovery branch July 7, 2026 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant