Search Unity

Unity can connect to remote server from editor but not from android device

Discussion in 'Multiplayer' started by OctoSharko, Sep 18, 2017.

  1. OctoSharko

    OctoSharko

    Joined:
    Dec 9, 2016
    Posts:
    35
    I am working on a multiplayer video game using Unity. I can successfully connect to a remote server using something like this :

    public string GetToken(string user, string pass)
    {
    string uri = _serverUrl + "/Token/" + user + "/" + pass;
    UnityWebRequest www = UnityWebRequest.Get(uri);

    www.Send();
    WaitForSeconds w;
    while (!www.isDone)
    w = new WaitForSeconds(0.1f);
    string token = null;
    JObject o = JObject.Parse(www.downloadHandler.text);
    token = o.First.First.ToObject<string>();

    return token;
    }
    This works fine when I am trying the code from the Unity Editor on my PC. I can successfully connect to the remote server which is in the WAN.

    However when I try to deploy the game on an Android device. The connection fails. (I have been carreful to add the full internet access permission before building the Android apk).

    Any idea what might be happening ?

    Thanks !
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Can you test with a browser on the device and get a simple page from the server?
     
  3. OctoSharko

    OctoSharko

    Joined:
    Dec 9, 2016
    Posts:
    35