How to communicate the port for AutoDiscovery

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 :woozy_face:

I’ve had a second view into the language reference for AutoDiscovery. It seems to me that the sample code contains an infinite loop:

Var success As Boolean = True
Do
  Try
    Me.Bind(Rnd * (65536 - 8192) + 8192)
  Catch error As RuntimeException
    success = False
  End Try
Loop Until success

I think the sample code must contain “success = true” behind the bind.

1 Like

Nope, the success is true by default
If an exception occourse it will retry.

do
/// code
loop until success

means loop at least once, if success = True it will stop

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).

1 Like

But the first RuntimeException will set success to false and success becomes not reset to true.

1 Like

It contains an error for sure. It should be:

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
2 Likes

Yes I think it too: I will create a editable preference for the port number.

Succes = False means keep looping.

Ahh i see yep @Rick_A

1 Like

If in the original code it does not bind at first attempt, it’ll never more get the success flag as true.

1 Like

Xojo should correct the sample code with your example!

Well there is no debugger in the forums (yet) :rofl:

I would prefer

Do
  Try
    Me.Bind(Rnd * (65536 - 8192) + 8192)
    Exit
  Catch
    // Port binding failed
  End Try
Loop
1 Like

I believe the correct code should be

Do
  Var success As Boolean = True
  Try
    Me.Bind (Rnd * (65536 - 8192) + 8192)
  Catch error As RuntimeException
    success = False
  End Try
Loop Until success

Has anyone filed a feedback report on this?

Let’s call @Paul_Lefebvre for a review and possible copy/paste

:thinking: This seems the same original wrong code

Do you not see this line?

I recommend :nerd_face: then … :wink:

Moving that one line means each time the loop is run success = true not just the first time as per the sample code.

I’ve added a feedback case <https://xojo.com/issue/61665> for this.

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.

3 Likes