/// <summary> /// AddMsgIdCall /// </summary> /// <param name="msgId"></param> /// <param name="call"></param> /// <param name="state"></param> public virtual void AddMsgIdCall(int msgId, MsgDataCall call, object state = null) { MsgIdCallModel callInfo = new MsgIdCallModel() { Id = msgId, Call = call, State = state }; this.MsgIdCallDic[msgId] = callInfo; }
/// <summary> /// 添加 cmd call /// </summary> /// <param name="cmd"></param> /// <param name="call"></param> /// <param name="state"></param> public virtual void AddCmdCall(int cmd, MsgDataCall call, object state = null) { MsgCmdCallModel callInfo = new MsgCmdCallModel() { Cmd = cmd, Call = call, State = state }; this.MsgCmdCallDic[cmd] = callInfo; }
/// <summary> /// 异步发送消息 /// </summary> /// <param name="cmd">需要发送的消息</param> /// <param name="data"></param> /// <param name="call">回调函数</param> /// <param name="state">传入数据</param> /// <returns>msgId</returns> public virtual int SendAsync <T>(int cmd, T data, MsgDataCall call, object state = null) { int msgId = this.GetMsgId(); MsgData msg = new MsgData() { Id = msgId, Cmd = cmd }; if (data != null) { msg.SetData(data); } if (call != null) { this.AddMsgIdCall(msgId, call, state); } var buffer = msg.Serialize(); buffer = OnEncrypt(buffer); this.tcpClient.Send(buffer); return(msgId); }