public async Task <RpcResult <RegisterRsp> > RegisterAsync(RegisterReq req, int timeOut = 3000) { AmpMessage message = AmpMessage.CreateRequestMessage(20003, 1); message.FriendlyServiceName = "UserService.Register"; message.Data = req.ToByteArray(); var response = await base.CallInvoker.AsyncCall(message, timeOut); if (response == null) { throw new RpcException("error,response is null !"); } var result = new RpcResult <RegisterRsp>(); if (response.Code != 0) { result.Code = response.Code; } if (response.Data == null) { result.Data = new RegisterRsp(); } else { result.Data = RegisterRsp.Parser.ParseFrom(response.Data); } return(result); }
public override void Execute(INotification notification) { int mainproto = int.Parse(notification.Name); CmdType type = (CmdType)Enum.Parse(typeof(CmdType), notification.Type); if (type == CmdType.Request) { Message message = notification.Body as Message; Notify notify = new Notify(); notify.Protocol = mainproto; switch (mainproto) { case Protocol.Login: LoginReq loginReq = ReferencePool.Require <LoginReq>(); loginReq.Account = message.args[0].ToString(); loginReq.Password = message.args[1].ToString(); notify.message = loginReq.ToByteArray(); NetworkManager.SendRequest(notify); break; case Protocol.Regist: RegisterReq registerReq = ReferencePool.Require <RegisterReq>(); registerReq.Account = message.args[0].ToString(); registerReq.Password = message.args[1].ToString(); notify.message = registerReq.ToByteArray(); NetworkManager.SendRequest(notify); break; } } }
//同步方法 public RpcResult <RegisterRsp> Register(RegisterReq req) { AmpMessage message = AmpMessage.CreateRequestMessage(20003, 1); message.FriendlyServiceName = "UserService.Register"; message.Data = req.ToByteArray(); var response = base.CallInvoker.BlockingCall(message); if (response == null) { throw new RpcException("error,response is null !"); } var result = new RpcResult <RegisterRsp>(); if (response.Code != 0) { result.Code = response.Code; } if (response.Data == null) { result.Data = new RegisterRsp(); } else { result.Data = RegisterRsp.Parser.ParseFrom(response.Data); } return(result); }