UNET - How to listen for StopBroadcastDiscovery() to finish? And can buffer be changed while BroadcastDiscovery is running?

Hi, I’m currently working on UNET NetworkTransport BroadcastDiscovery.

I’m using a modified version of this example.

However, if I call StopBroadcastDiscovery() and ask for NetworkTransport.IsBroadcastDiscoveryRunning() immediately afterwards, true is being returned.

Is this an asynchronous call?
If so, how can I get notified about the Discovery having finished the stopping process?

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Also, is it possible to change the broadcast data while the service is running?
I tried the following:

  1. Stop()
  2. Change msgBuffer
  3. Start()

, but this resulted in the following error:

Broadcast discovery has been already running. Stop discovery first before repeat this call

Looks like this has also to do with my first question (see above).

edit:

Yep, Start and Stop seem to be asynchronous. If I waitForSeconds between the Stop() and Start() call, it works as expected. However, waitForSeconds is a dirty hack.

I still would like to know, if I can change the broadcasting data without restarting the service and / or if and how I can listen for Stop() to be finished.

Cheers,
phineliner

I didn’t find a way to change the broadcast data while broadcast discovery is running.

But I solved the problem by doing the following:

  1. Prepare buffer with new data
  2. StopBroadcastDiscovery()
  3. while(not stopped) wait a frame
  4. StartBroadcastDiscovery()

This way I can listen for Stop() to finish and then safely Start() the service again.

See code example:

    //preparing msgBuffer in advance... then StartCoroutine(RestartServiceRoutine())

    public IEnumerator RestartServiceRoutine()
    {
        if (IsRunning())
        {
            StopService();

            //wait for service to be stopped, before starting again
            while (NetworkTransport.IsBroadcastDiscoveryRunning())
                yield return 0;

            StartService();
        }
    }

Hope this helps somebody else!

Cheers, phineliner

bug 742022 filed for this.