Beispiel #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();
    }
Beispiel #2
0
    static void Main(string[] args)
    {
        // 初始化 PKG 模板生成物代码 序列化的 id:type 映射
        PKG.AllTypes.Register();

        // 创建 libuv 运行核心循环
        var loop = new xx.UvLoop();

        // 初始化 rpc 管理器, 设定超时参数: 精度(ms), 默认超时 ticks( duration = 精度ms * ticks )
        loop.InitRpcManager(1000, 5);

        // 初始化 peer活动 超时管理器. 精度ms, 计时 ticks 最大值, 默认 ticks ( duration = 精度ms * ticks )
        loop.InitTimeoutManager(1000, 30, 5);

        // 创建登陆服务实例
        var loginService = new LoginService(loop);

        Console.WriteLine("server_login running...");

        // 开始运行
        loop.Run();
    }