[1] https://chaosnet.net/protocol#application_layer [2] https://datatracker.ietf.org/doc/html/rfc1078
I have never faced this problem even though I hard-code the port. It's because I run the server program through VS Code's debugger. If there's already a session, it would warn me.
Not super popular, but: https://en.wikipedia.org/wiki/SRV_record
But at a larger level this tool just makes everything work so smoothly. If you have two services with the same name, it pops up a notification in the tray. If you start a new process with a different name, you don't have to configure SRV; the DNS just becomes available automatically. HTTPS is auto configured. That sort of thing.
I think somebody could one day make something like this that was based on SRV, but it would still need all those niceties to make it work well for developers.
- old / zombie server processes
- sockets that weren't properly cleaned up
- TIME_WAITs
my solution wasn't anything as clever as OPs though. Basically, I ended up conceiving of 127/8 as a rotating ring. Where you can pass offsets and easily end up on an unused bind tup every time. 127/8 gives you a huge number of IPs to play with. You just make address handling part of your test launcher and it sets a new IP each time.
The issue is it doesn't really work for IPv6 (v6 localhost is only one address!) Though global-scope v6 interface blocks and manually assigned link-local scope, you could accomplish much the same thing.