Example #1
0
    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;
    }
Example #2
0
    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;
    }