コード例 #1
0
    static void Main(string[] args)
    {
        PKG.AllTypes.Register();
        var loop = new xx.UvLoop();

        loop.InitRpcManager(1000, 10);
        loop.InitTimeoutManager(1000, 30, 5);
        var client = new xx.UvTcpClient(loop);

        client.SetAddress("127.0.0.1", 10001);
        client.OnConnect = status =>
        {
            if (status != 0)
            {
                Console.WriteLine("connect to server_login failed. status = " + status);
                return;
            }
            Console.WriteLine("connected.");

            var a = new PKG.Client_Login.Auth {
                username = "******", password = "******"
            };
            if (System.Environment.TickCount % 5 == 0)
            {
                a.password = "******";
            }
            client.SendRequestEx(a, recv =>
            {
                if (recv == null)
                {
                    Console.WriteLine("recv == null( timeout )");
                    return;
                }
                Console.WriteLine("PKG.Client_Login.Auth recv: " + recv);

                switch (recv)
                {
                case PKG.Generic.Error o:
                    client.Disconnect();
                    break;

                case PKG.Generic.Success o:
                    break;

                default:
                    break;
                }
            });
        };
        var timer = new xx.UvTimer(loop, 1000, 2000, () =>
        {
            if (client.state == xx.UvTcpStates.Disconnected)
            {
                Console.WriteLine("connect to server_login...");
                client.Connect();
            }
        });

        loop.Run();
    }
コード例 #2
0
ファイル: Program.cs プロジェクト: denghe/xxlib_csharp
    public LoginService(xx.UvLoop loop)
    {
        listener = new xx.UvTcpListener(loop);
        listener.Bind("0.0.0.0", 10001);
        listener.Listen();
        listener.OnAccept = OnAccept;

        dbClient = new xx.UvTcpClient(loop);
        dbClient.SetAddress("127.0.0.1", 10000);
        dbClient.OnConnect = OnDbClientConnect;

        // 延迟 500ms 后每 500ms 触发一次
        timer = new xx.UvTimer(loop, 500, 500, OnTimerFire);
    }