1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. Unity 5.6 is now released.
    Dismiss Notice
  3. Check out all the fixes for 5.5 in patch releases 1 & 2.
    Dismiss Notice
  4. Get further faster with the Unity Plus Accelerator Pack, free for new Unity Plus subscribers for a limited time. Click here for more details.
    Dismiss Notice
  5. Learn how you'll soon be able to publish your games to China in four simple steps with Xiaomi. Sign up now for early access.
    Dismiss Notice

Can't receive broadcast message, can anyone help?

Discussion in 'Multiplayer Networking' started by gon777, Mar 15, 2017.

  1. gon777

    gon777

    Joined:
    Dec 20, 2016
    Posts:
    5
    Hi,
    I was able to receive broadcast message yesterday but I have no idea how I broke it :(
    My execution sequence is:

    On my game instance -> call MylobbyManager.instance.Starthost(),
    Then on my editor -> call MylobbyManager.instance.ClientStartListening()

    Can anyone help me look at the code and tell me what is wrong?
    Your help will be much appreciated.

    MyLobbyManager
    Code (CSharp):
    1.      
    2. public class MyLobbyManager : NetworkLobbyManager {
    3.     public static MyLobbyManager instance = null;
    4.     public MyNetworkDiscovery myNetworkDiscovery;
    5.  
    6.     public void Start(){
    7.         if (instance == null) {        
    8.             instance = this;
    9.         } else {      
    10.             Destroy (gameObject);
    11.         }
    12.     }
    13.  
    14.     public override void OnStartHost ()
    15.     {
    16.         base.OnStartHost ();
    17.         myNetworkDiscovery.Initialize ();
    18.         myNetworkDiscovery.StartAsServer ();
    19.     }
    20.  
    21.     public void ClientStartListening(){
    22.         myNetworkDiscovery.Initialize ();    
    23.         myNetworkDiscovery.StartAsClient ();
    24.     }
    25.   }
    26. }
    27.  
    mylobbymanager1.png mylobbymanager2.png

    MyNetworkDiscovery
    Code (CSharp):
    1.  
    2. public class MyNetworkDiscovery : NetworkDiscovery {  
    3.     public override void OnReceivedBroadcast (string fromAddress, string data){
    4.         base.OnReceivedBroadcast (fromAddress, data);
    5.         Debug.Log ("Got Message from (" + fromAddress + ") and (" + data + ")");
    6.     }
    7. }
    8.  
    networkdiscovery.png
     
    Last edited: Mar 15, 2017
  2. gon777

    gon777

    Joined:
    Dec 20, 2016
    Posts:
    5
    Turns out you need to call Initilise() and StartAsServer() AFTER calling StartHost(), not in OnStartHost()
     
  3. gon777

    gon777

    Joined:
    Dec 20, 2016
    Posts:
    5
    Also make sure you linked correct NetworkDiscovery reference in editor