Search Unity

Resolved [NETCODE] Android client & Multiplay server

Discussion in 'Netcode for GameObjects' started by morgaxis, Dec 20, 2022.

  1. morgaxis

    morgaxis

    Joined:
    May 25, 2020
    Posts:
    10
    Hi,
    Just want to share few information, as I spent lot of time to have this running ok, maybe it can help

    • unity 2022.2.0f1
    • IL2CPP
    • Multiplay 1.0.0-pre.6
    • netcode 1.2.0


    1) running both client & server on my local PC from editor or batch mode with 192.168.1.100 as @ip was ok
    Netcode client ,running on editor or batch mode
    For local tests
    IPAdress = "192.168.1.100";
    IPList = "192.168.1.100";
    defaultPort = 9000;
    netManager.GetComponent<UnityTransport>().SetConnectionData(IPAdress, (ushort)defaultPort, IPList);

    Netcode Server, build dedicated server windows started with a batch
    IPAdress = "0.0.0.0";
    IPList = "0.0.0.0";
    defaultPort = 9000;
    netManager.GetComponent<UnityTransport>().SetConnectionData(IPAdress, (ushort)defaultPort, IPList);

    2) running the client on Android tab using WIFI , server still on local pc, Client use the @ip of the server
    was not working

    Netcode client, build on Android (Galaxy Tab A10)
    For local tests
    IPAdress = "192.168.1.100";
    IPList = "192.168.1.100";
    defaultPort = 9000;
    netManager.GetComponent<UnityTransport>().SetConnectionData(IPAdress, (ushort)defaultPort, IPList);

    Netcode Server, build standalone windows
    IPAdress = "0.0.0.0";
    IPList = "0.0.0.0";
    defaultPort = 9000;
    netManager.GetComponent<UnityTransport>().SetConnectionData(IPAdress, (ushort)defaultPort, IPList);

    check connectivity between Android & PC using Android tcp/udp widget and wireshark on PC
    was ok ==> so problem was the Unity android APP not able to send packets or ?
    I finally found that the parameter ==> Project settings/Player / Internet access must be set to require and not auto

    3) running the client on Android, Uploaded a server build on multiplayer cloud
    Netcode client, build on Android (Galaxy Tab A10)
    For Internet tests
    IPAdress = "xxxxxxx"; <= the one given by Unity dashboard on test allocation
    IPList = "xxxxxx"; <= the one given by Unity dashboard on test allocation
    defaultPort = 9000;
    netManager.GetComponent<UnityTransport>().SetConnectionData(IPAdress, (ushort)defaultPort, IPList);

    Netcode Server, build dedicated server Linux
    IPAdress = "0.0.0.0"; <== Here I force inside the server code, I don't use the @given by $$ip$$
    IPList = "0.0.0.0";
    defaultPort = 9000;

    And it work !

    Hope it will help
     
    ADNOC_LNG likes this.
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,886
    If your PC is wired to the router, while the other device uses the router's wifi, they will (normally) be in different sub nets. Thus the server IP is inaccessible to wifi devices for direct communication.

    To fix this you'd have to disable "wifi isolation" and add port forwarding to the router's config so that the router knows that the server address routes to the wired network (*). Essentially the same as allowing a device to connect through the internet with your local pc.

    *= it may also be possible to put both wifi and wired devices on the same subnet depending on the router, or set it up so it behaves as if they were in the same subnet.
     
    morgaxis likes this.
  3. morgaxis

    morgaxis

    Joined:
    May 25, 2020
    Posts:
    10
    Good info, thanks,
    was not my case, both are on same subnet, my problem was link to the internet option AUTO/REQUIRE :-<
     
  4. AhmadGhodrati

    AhmadGhodrati

    Joined:
    Jun 30, 2023
    Posts:
    1
    been doing random stuff for 3 days no clue what i was doing. and this saved me :D
     
  5. Aladinho

    Aladinho

    Joined:
    Jul 18, 2013
    Posts:
    9
    If somebody try set internet to require and still not work. Make sure you not run server in editor. Seem like editor can't receive connection from other device