1
\$\begingroup\$

I am trying to get the broadcasted message in overridden method of NetworkDiscovery.OnReceivedBroadcast(). For that what I had done is below:

  1. I create class which implements NetworkDiscovery where I override the method OnReceivedBroadcast() to capture the broadcast messages.
  2. In Unity Editor, I created an empty GameObject where I add the class in step #1 as component.

Now in code, I started the custom NetworkDiscovery class as below:

Discovery.Initialize();
Discovery.StartAsClient();

Now, when I start the broadcast in server, I am not receiving any broadcast message in OnReceivedBroadcast().

Below is my custom NetworkDiscovery class.

public class CustomNetworkDiscovery : NetworkDiscovery
{

// Use this for initialization
void Start()
{

}

// Update is called once per frame
void Update()
{

}

public override void OnReceivedBroadcast(string fromAddress, string data)
{
    base.OnReceivedBroadcast(fromAddress, data);
}
}

One thing I noted is, If I use the NetworkDiscovery component directly in step #2; instead of using custom NetworkDiscovery class. I am able to see broadcast messages in it's default GUI.

How can I receive the broadcast message in the inherited class?

Any help will be appreciated. Thanks.

\$\endgroup\$
1
\$\begingroup\$

I had the same problem. Turns out the class that inherits from NetworkDiscovery is not allowed to have it's own Update() function.

\$\endgroup\$
0
\$\begingroup\$

I suggest to use source code of the network discovery. In their script there is a void OnGUI() method that controls the GUI control.

\$\endgroup\$
0
\$\begingroup\$

I have the same issue but I solved it by un-checking the "Use NetworkManager" and add anything in the broadcast data. I can pass now any data inside my script like

discovery.broadcastData = "Hello World"

The only problem is you can only broadcast data at once. right after that you are unable to update the broadcasted message

\$\endgroup\$
-1
\$\begingroup\$

Refer this thread for solution http://forum.unity3d.com/threads/onreceivedbroadcast-doesnt-supply-port-number.381833/

\$\endgroup\$
1
  • \$\begingroup\$ Please summarize the main points that you hope a reader will learn from this thread in the text of your answer itself. That way the answer will continue to be useful even if the link becomes unavailable in the future. \$\endgroup\$ – DMGregory Jul 21 '18 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.