1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  3. We’re giving 2017.1 beta testers a chance to win t-shirts and a Nintendo Switch. Read more on the blog.
    Dismiss Notice
  4. We want to know how you learned Unity! Help us by taking this quick survey and have a chance at a $25 gift card
    Dismiss Notice
  5. Unity 5.6 is now released.
    Dismiss Notice
  6. Check out all the fixes for 5.6 on the patch releases page.
    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