/// <summary> /// 连接服务器 /// </summary> private static async void ConnectAsync() { var ex = await remote.ConnectAsync(new IPEndPoint(IPAddress.IPv6Loopback, 54321)); remote.ReceiveCallbackMgr = new ReceiveCallbackMgr(); if (ex == null) { //没有异常,连接成功 Console.WriteLine("连接成功"); //创建一个登陆消息 var login = new Login2Gate() { Account = $"TestClient", Password = "******" }; //有返回值,这个是一个RPC过程,Exception在网络中传递 var resp = await remote.SendAsyncSafeAwait <Login2GateResult>(login); if (resp.Code == EnumRpcCallbackResultStatus.Success) { Console.WriteLine("登录成功"); } else { Console.WriteLine("登录失败"); } //没有返回值,不是RPC过程 } else { //连接失败 Console.WriteLine(ex.ToString()); } }
protected override async Task ExecuteAsync(object parameter) { if (await _remote.ConnectAsync().ConfigureAwait(false)) { } }