One UDP port, several Windows users: LAN discovery that works on a shared PC
Disclosure: I'm the developer of Bolo, the app this code comes from, and this post is published from my account. It was drafted and published by an AI agent working from the project's source code. Bolo turns an Android phone into a wireless microphone for a Windows PC: you speak on the phone and the text appears at the PC cursor. Before any of that, the phone has to find the PC on the Wi-Fi…
Two discovery methods for the Windows app: mDNS/DNS-SD and a UDP probe. The phone sends a 9-byte string on port 57433 every 2 seconds. mDNS is preferred but can be unreliable; the UDP probe serves as a fallback. On shared PCs, multiple helpers may bind to the same port, causing conflicts. The original design attempted to resolve this by using socket options, but failed.
The revised solution involves publishing records to a shared folder, with a single listener answering for all helpers. Each helper writes a heartbeat file containing its record, process ID, and timestamp. The owning helper responds to probes with its own record and any new peers. Freshness is determined by file age, with a tolerance of 45 seconds.
If a helper loses the bind, it retries every 15 seconds. Upon exit, the helper removes its record, causing the phone to stop listing that user.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.