The language reference shows a way to find a free port for AutoDiscovery but says “…you need to find a way to communicate this port to the others…”.
Does somebody knows a way to communicate this port to the other apps of the registered group?
I.e. should I write a file to a network storage? I don’t like this, but I have no other idea except to type the port into a field of every app or use a hard wired port
I think you best option would be to have a fixed, port number and some kind of setting where it can be changed if it failed too much (perhaps a timer or something to check).
The above is actually not that stable as it could be really slow to get a port and changes alot (each run , which can be hard to debug).
Var success As Boolean = False
Do
Try
Me.Bind(Rnd * (65536 - 8192) + 8192)
success = True
Catch error As RuntimeException
// Port binding failed, success still false
End Try
Loop Until success
Ah, ok. Inside the loop it works, but in such format it is a bad design, because it means unnecessary allocation, setting values, and destruction, of such variable at every cycle.
The docs page for AutoDiscovery is a hot mess. It seems to be leaking events and methods from UDPSocket and EasyUDPSocket that are not relevant to AutoDiscovery, and can be confusing to the user. AutoDiscovery is meant to be simple and shouldn’t be cluttered with lower-level details.