예제 #1
0
        /// <summary>
        /// 连接服务器
        /// </summary>
        private static async void ConnectAsync()
        {
            IRemote remote = new TcpRemote();
            var     ex     = await remote.ConnectAsync(new IPEndPoint(IPAddress.IPv6Loopback, 54321));

            if (ex == null)
            {
                ///没有异常,连接成功
                Console.WriteLine("连接成功");

                ///创建一个登陆消息
                var login = new Login2Gate
                {
                    Account  = $"TestClient",
                    Password = "******"
                };

                ///有返回值,这个是一个RPC过程,Exception在网络中传递
                var resp = await remote.SendAsyncSafeAwait <Login2GateResult>(login);

                if (resp.IsSuccess)
                {
                    Console.WriteLine("登陆成功");
                }

                ///没有返回值,不是RPC过程
            }
            else
            {
                ///连接失败
                Console.WriteLine(ex.ToString());
            }
        }
예제 #2
0
        public async void TestAsync2()
        {
            TcpRemote remote = new TcpRemote();
            var       res    = await remote.SendAsyncSafeAwait <TestPacket1>(null);

            res.ToString();
            await Task.Delay(10);

            res.ToString();
        }