public IEnumerator ConnectToServer() { string host = "139.59.127.218"; // string host = "localhost"; // string host = "192.168.1.3"; int port = 3456; DGTPacket.Config pc = new DGTPacket.Config(host, port); DGTRemote.resetGameState(); DGTRemote gamestate = DGTRemote.GetInstance(); gamestate.Connect(pc.host, pc.port); gamestate.ProcessEvents(); yield return(new WaitForSeconds(0.1f)); for (int i = 0; i < 10; i++) { if (gamestate.Connected()) { break; } if (gamestate.ConnectFailed()) { break; } gamestate.ProcessEvents(); yield return(new WaitForSeconds(i * 0.1f)); } if (gamestate.Connected()) { Debug.Log("Connected Finish"); // send login gamestate.RequestLogin(); gamestate.mainController = this; // SceneManager.LoadScene("PlayScene"); } else { yield return(new WaitForSeconds(5f)); Debug.Log("Cannot connect"); } // StartCoroutine(PingTest()); yield break; }
public IEnumerator ConnectToServer() { DGTPacket.Config pc = new DGTPacket.Config("localhost", 3456); DGTRemote.resetGameState(); DGTRemote gamestate = DGTRemote.GetInstance(); gamestate.Connect(pc.host, pc.port); gamestate.ProcessEvents(); yield return(new WaitForSeconds(0.1f)); for (int i = 0; i < 10; i++) { if (gamestate.Connected()) { break; } if (gamestate.ConnectFailed()) { break; } gamestate.ProcessEvents(); yield return(new WaitForSeconds(i * 0.1f)); } if (gamestate.Connected()) { Debug.Log("Login Finish"); // send login gamestate.RequestLogin(); gamestate.mainController = this; } else { yield return(new WaitForSeconds(5f)); Debug.Log("Cannot connect"); } // StartCoroutine(PingTest()); yield break; }
public IEnumerator ConnectToServer(string ipaddress, int port) { DGTPacket.Config pc = new DGTPacket.Config(ipaddress, port); //connect to server IP,port DGTRemote.resetGameState(); DGTRemote gamestate = DGTRemote.GetInstance(); gamestate.Connect(pc.host, pc.port); //IP host, port to serve gamestate.ProcessEvents(); //Process Event yield return(new WaitForSeconds(0.1f)); for (int i = 0; i < 10; i++) { if (gamestate.Connected()) { break; } if (gamestate.ConnectFailed()) { break; } gamestate.ProcessEvents(); yield return(new WaitForSeconds(i * 0.1f)); } if (gamestate.Connected()) { Text status = GameObject.Find("s1_status").GetComponent <Text>(); status.text = "Online"; status.color = Color.green; gamestate.mainController = this; } else { yield return(new WaitForSeconds(5f)); Debug.Log("Cannot connect"); } //StartCoroutine(PingTest()); yield break; }