Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Unity Multiplayer LAN Network Discovery not working

Discussion in 'Connected Games' started by Xuzon, Oct 27, 2016.

  1. Xuzon

    Xuzon

    Joined:
    Mar 21, 2014
    Posts:
    83
    Hello, I have a weird problem.

    If I use the default network manager HUD I can connect from one PC to another in the same Local Area Network but when I make my own weird things happen.

    I've inherited the Network Discovery
    Code (CSharp):
    1. public class NDiscovery :NetworkDiscovery{
    2.     protected bool connected = false;
    3.     public override void OnReceivedBroadcast(string fromAddress, string data) {
    4.         if (!connected) {
    5.             NetworkManager.singleton.networkAddress = fromAddress;
    6.             print(fromAddress);
    7.             print(data);
    8.             print("ADD:" + NetworkManager.singleton.networkAddress+" PORT:" + NetworkManager.singleton.networkPort);
    9.             NetworkManager.singleton.StartClient();
    10.             connected = true;
    11.         }
    12.     }
    13.  
    14. }
    OnStartHost I just initialize that and StartAsServer and with a custom button I hit NDiscovery.Initialize and NDiscovery.StartAsClient

    The weird thing comes when I receive a Broadcast Message:
    The fromAddress is fine but the data is NetworkManager:localhost:7777
    no problem with that, I've just used the fromAddress and set it on NetworkManager but when it starts the client, the client can't connect to server.

    In the same PC I have no problem with this but in two separate PCs in the same LAN the client can't connect with the host.
    The client doesn't even try to load the loaded scene in the server.

    Any ideas of what is happening here?

    [EDIT]
    I've just tried to connect from client to server just typing the IP address and calling the NetworkManager.singleton.StartClient() and didn't work, but with the MatchMaking and relay servers works perfectly, I don't know what is happening

    (Yes the two PCs are in the same Wifi and their ip addresses are 192.168.1.101 (server) 192.168.1.102 (client) )

    Checked the ports opened in the Server and UDP [::]:7777 is listening so, I don't know why it isn't answering

    I've just sniffed the traffic in the LAN and the client is trying to connect to server but server never answers
     
    Last edited: Oct 27, 2016
  2. eltronix

    eltronix

    Joined:
    Sep 6, 2016
    Posts:
    4
  3. Xuzon

    Xuzon

    Joined:
    Mar 21, 2014
    Posts:
    83
    Hi!!
    I've just found the error that was causing this weird error

    The windows firewall in the local server was causing the server not answering, anyone knows a way to fix that not being stoping the windows firewall at all or deactivating it? because in the test we could make that but when we will release the game we want that people could host their own LANs
     
  4. Akki-bhatt

    Akki-bhatt

    Joined:
    Jul 8, 2017
    Posts:
    19
    hey @8NeonBitGuy

    I think it's too late but I feel it might help you.
    go here.
     
  5. amelierosser

    amelierosser

    Joined:
    Feb 2, 2018
    Posts:
    1
    Thank you!