title: UNET: connect client to host using ip and port
body: <p>I'm trying to create my first multiplayer game using UNET where one of the players is always hosting. I planned to do host migration to keep the game going even if the host leaves. Is this even a good idea in general?</p>
  
  <p>So far I have a function that creates a new room (players starts to host a room), which looks like this:</p>
  
  <pre><code>public void Test_StartHost(){
      if (!NetworkClient.active &amp;&amp; !NetworkServer.active &amp;&amp; manager.matchMaker == null) 
      {
          string ip = Network.player.ipAddress.Replace (".", "|");
          string port = Network.player.port.ToString();
  
          db.save(ip + "&lt;&lt;" + port);
  
          NetworkManager.StartHost ();
      }
  }
  </code></pre>
  
  <p>This is tested and working (host's game starts and database receives the data). I've tested hosting on both Android and PC. Both of the devices send different IP (<strong>xxx.xxx.xx.xxx</strong>) but same port <strong>0</strong> to the database. Can the port <strong>0</strong> be correct?</p>
  
  <p>Next thing that happens is that another player tries to join the game as client. For that I have this code:</p>
  
  <pre><code>public void Play()
  {
      if (!NetworkClient.active &amp;&amp; !NetworkServer.active &amp;&amp; manager.matchMaker == null) 
      {
          string hostIP = database.get("hostIP"); // xxx.xxx.xx.xxx
          int hostPort = int.Parse(database.get("hostPort")); // 0
  
          Debug.Log("Trying to join IP " + hostIP + " as a client. Listening to port " + hostPort + ".");
          // prints "Trying to join IP xxx.xxx.xx.xxx as a client. Listening to port 0.
  
          NetworkManager.networkAddress = hostIP;
          //NetworkManager.networkPort = hostPort;
  
          NetworkManager.StartClient();
      }
  }
  </code></pre>
  
  <p>Joining the game works <strong>IF</strong> both of the devices are in the same Wi-Fi. If PC (host) uses Wi-Fi and Android tries to join the room (using mobile network) I always get timeout error after ~15 seconds.</p>
  
  <p>Why does this work only on the same Wi-Fi and not over different internet connections?</p>