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