Example #1
0
    private IEnumerator LoginCoroutine(string user)
    {
        _Status = "Connecting ...";

        Game game = Game.GetInstance();

        game.ClearRemote();

        Packet.Config pc     = game.GetNetworkConfig();
        Remote        remote = new Remote();

        remote.Connect(pc.host, pc.port);
        remote.ProcessEvents();
        yield return(new WaitForSeconds(0.1f));

        for (int i = 0; i < 10; i++)
        {
            if (remote.Connected())
            {
                break;
            }
            if (remote.ConnectFailed())
            {
                break;
            }

            remote.ProcessEvents();
            yield return(new WaitForSeconds(i * 0.1f));
        }

        if (remote.Connected())
        {
            _Status = "Connected ...";

            // send login
            Packet packet = remote.GetPacket();
            packet.SendLogin(user);

            game.SetRemote(remote);

            _Status = "Loading ...";
            Application.LoadLevel("Chat");
        }
        else
        {
            _Status = "Connect Fail ...";
        }
    }
Example #2
0
    private void LoginThread(string user)
    {
        Game game = Game.GetInstance();

        game.ClearRemote();

        Packet.Config pc     = game.GetNetworkConfig();
        Remote        remote = new Remote();

        remote.Connect(pc.host, pc.port);
        remote.ProcessEvents();
        Thread.Sleep(1000);
        for (int i = 0; i < 10; i++)
        {
            if (remote.Connected())
            {
                break;
            }
            if (remote.ConnectFailed())
            {
                break;
            }

            remote.ProcessEvents();
            Thread.Sleep(50 * i);
        }

        if (!remote.Connected())
        {
            return;
        }

        // send login
        Packet packet = remote.GetPacket();

        packet.SendLogin(user);

        game.SetRemote(remote);
    }