int CAceTCPClient::SendJsonRsp(Cjson jsonRsp,int MsgID,int CheckKeyServer,int sendTimes){ if(ifUseJson == 0){ AfxMessageBox("未设置使用json模式"); return 0; } //设置消息号 jsonRsp["MsgID"] = MsgID; //如果客户端回复发包 jsonRsp["CheckKeyServer"] = CheckKeyServer; //发送回复包 CString strSendJson = jsonRsp.tostring("","").c_str(); return ppeer->send((LPSTR)(LPCTSTR)strSendJson,strSendJson.GetLength()); //发送数据 }
int CAceTCPClient::SendJsonReq(Cjson jsonReq,int MsgID,Cjson jsonCheckPackage,int nDeleteTime,int sendTimes){ if(ifUseJson == 0){ AfxMessageBox("未设置使用json模式"); return 0; } //设置消息号 jsonReq["MsgID"] = MsgID; //如果客户端主动发包则加上寄存钥匙 jsonReq["CheckKeyClient"] = ++CheckKeyClient; //根据钥匙把包裹存入map中 mapCheck[CheckKeyClient] = jsonCheckPackage; //定时器,过一定时间之后把对应的包裹删除,防止出现因为网络不好对面不回信息的情况 CDeleteMapWatch* pWatch = new CDeleteMapWatch; WatchPac* ppackage = new WatchPac; ppackage->CheckKeyClient = CheckKeyClient; ppackage->pThis = this; pWatch->CountDown(nDeleteTime * 1000,ppackage); //发送 CString strSendJson = jsonReq.tostring("","").c_str(); return ppeer->send((LPSTR)(LPCTSTR)strSendJson,strSendJson.GetLength()); //发送数据 }