App Dev · · 3 min read
NetLay: Just me, or everyone?
The portable folder always listened on localhost and nobody else could reach it, so now it asks one question at startup and deals with the Windows firewall for you.
One question#
The portable build from post five listens on localhost. That means the person who unzipped it can use it and nobody else can, which is right about half the time and wrong the other half, and I had made that decision for everybody by not thinking about it.
So start.cmd asks.
How should NetLay run? [1] Just this PC [2] Share on the network
Enter takes whatever you chose last time, and the answer is remembered along with the port. For people who never want to be asked there is a start-local.cmd and a start-shared.cmd, and a port switch for when something else already has eight thousand and ten.
The actual difference between those two modes is one flag, the address the server binds to. Everything else in this post exists because that one flag is not enough on Windows.
Making shared actually work.#
If you tell somebody the application is shared, they need to know what to type. So shared mode prints the addresses that will work: the machine name with the port, and one line per IPv4 address it finds, skipping loopback and the self-assigned ones that never help anybody.
Then there is the firewall, which will otherwise silently drop every connection while the server sits there looking perfectly healthy. That is the worst kind of failure, because nothing anywhere reports an error. The launcher offers to add a single inbound rule for the port, which triggers the usual Windows elevation prompt, and it only applies to the domain and private profiles.
Public networks deliberately do not get the rule. If the current network is set to public it says so and explains that the rule will not apply there, because the right behaviour in a coffee shop is for this thing not to be reachable, and the right behaviour is also to say that out loud rather than leaving somebody debugging a connection that is being dropped on purpose.
It also checks whether the port is already in use before starting, and says that NetLay may already be running, which is the answer about four times in five.
Why I am comfortable with this.#
Opening a port on a machine is not a thing to do casually, and it is only acceptable here because post six already happened.
Accounts exist. Everyone signs in. Layouts belong to their owner and are only visible to people they have been shared with, and that is enforced on the server rather than hidden in the interface. The shared mode window says all of that while it starts, so nobody is sharing a network map with the office under the impression that it is still their private copy.
If these had arrived in the other order, this post would have been a mistake.
While I was there, the development script flipped the other way. It used to bind to all interfaces in production mode, which was a sensible default for exactly nobody, and now it is local only unless you explicitly ask it to share.
Testing a launcher.#
Launchers are awkward to test automatically, so I tested this one by hand and wrote down what I checked.
Running the real launcher out of a real bundle, in each mode, and then looking at what the machine was actually listening on. Just this PC gave 127.0.0.1 and nothing else. Shared gave all interfaces, with the machine name and addresses printed correctly. And running it where there is no console to answer the question, which happens when somebody launches it from a scheduler or a shortcut, falls back to the last remembered choice rather than hanging forever waiting for an answer nobody is there to give.
That last case is the one that would have embarrassed me, and I only thought of it because I had just spent two posts finding bugs by using the thing rather than reasoning about it.
Next time, the most persistent lie in network documentation, which is that a device is its IP address.