本文整理汇总了C++中CTcpSocket::Send方法的典型用法代码示例。如果您正苦于以下问题:C++ CTcpSocket::Send方法的具体用法?C++ CTcpSocket::Send怎么用?C++ CTcpSocket::Send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CTcpSocket
的用法示例。
在下文中一共展示了CTcpSocket::Send方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doProcess
int doProcess(CTcpSocket &acpsocket)
{
int ret = 0;
int send_len = 0;
char recv_buf[4096] = "";
char send_buf[4096] = "";
acpsocket.Recv(recv_buf, sizeof(recv_buf), g_para.bank_timeout);
ret=strlen(recv_buf);
writelog(LOG_INFO,"len[%d],recv_buf[%s]\n",ret,recv_buf);
ret = doResponse(recv_buf,strlen(recv_buf),send_buf,send_len);
if(ret)
{
if(ret>0)
return ret;
}
send_buf[send_len]=0;
writelog(LOG_INFO,"len[%d],send_buf[%s]\n",send_len,send_buf);
ret = acpsocket.Send(send_buf,send_len);
if(ret != send_len)
{
writelog(LOG_ERR,"发送数据错误\n");
return -1;
}
return 0;
}
示例2: doProcess
int doProcess(CTcpSocket &acpsocket)
{
printf("\n doProcess3 \n");
int ret = 0;
int pack_len = 0;
int send_len = 0;
char recv_buf[4096] = "";
char send_buf[4096] = "";
//ret = acpsocket.Recv(recv_buf, HEAD_LEN, g_para.bank_timeout);
//ret = acpsocket.Recv(recv_buf, 2048, g_para.bank_timeout);
//ret = acpsocket.Recv(recv_buf, sizeof(recv_buf), g_para.bank_timeout);
acpsocket.Recv(recv_buf, sizeof(recv_buf), g_para.bank_timeout);
ret=strlen(recv_buf);
printf("\n recv_buf[%s] \n len[%d] ret[%d]\n",recv_buf,strlen(recv_buf),ret);
// if(ret != HEAD_LEN)
// {
// writelog(LOG_ERR,"接收银行数据包头错误\n");
// return -1;
// }
// pack_len = atoi(recv_buf);
// ret = acpsocket.Recv(recv_buf, pack_len, g_para.bank_timeout);
// if(ret != pack_len)
// {
// writelog(LOG_ERR,"接收银行数据包体错误\n");
// return -1;
// }
// recv_buf[pack_len]=0;
writelog(LOG_INFO,"len[%d],recv_buf[%s]\n",ret,recv_buf);
ret = doResponse(recv_buf,pack_len,send_buf,send_len);
if(ret)
{
if(ret>0)
return ret;
}
send_buf[send_len]=0;
writelog(LOG_INFO,"len[%d],send_buf[%s]\n",send_len,send_buf);
ret = acpsocket.Send(send_buf,send_len);
if(ret != send_len)
{
writelog(LOG_ERR,"发送数据错误\n");
return -1;
}
return 0;
}
示例3: doProcess
int doProcess(CTcpSocket &acpsocket)
{
int ret = 0;
int pack_len = 0;
int send_len = 0;
char recv_buf[256] = "";
char send_buf[256] = "";
ret = acpsocket.Recv(recv_buf, HEAD_LEN, g_para.bank_timeout);
if(ret != HEAD_LEN)
{
writelog(LOG_ERR,"接收银行数据包头错误\n");
return -1;
}
pack_len = atoi(recv_buf);
ret = acpsocket.Recv(recv_buf, pack_len, g_para.bank_timeout);
if(ret != pack_len)
{
writelog(LOG_ERR,"接收银行数据包体错误\n");
return -1;
}
recv_buf[pack_len]=0;
writelog(LOG_INFO,"len[%d],recv_buf[%s]\n",ret,recv_buf);
ret = doResponse(recv_buf,pack_len,send_buf,send_len);
if(ret)
{
if(ret>0)
return ret;
}
send_buf[send_len]=0;
writelog(LOG_INFO,"len[%d],send_buf[%s]\n",strlen(send_buf),send_buf);
ret = acpsocket.Send(send_buf,send_len);
if(ret != send_len)
{
writelog(LOG_ERR,"发送数据错误\n");
return -1;
}
return 0;
}
示例4: send_to_bank
static int send_to_bank(const std::string& req, std::string& resp)
{
int timeout = 0;
string ytc_ip;
int ytc_port;
int ret;
ret = get_ec_para(YTCEC_TIMEOUT, timeout);
if (ret)
{
LOG(ERROR, "中银通超时时限未配置");
return E_COMMON_ERR;
}
timeout*=1000;
ret = get_ec_para(YTCEC_SVRIP, ytc_ip);
if (ret)
{
LOG(ERROR, "中银通前置机未配置");
return E_COMMON_ERR;
}
ret = get_ec_para(YTCEC_SVRPORT, ytc_port);
if (ret)
{
LOG(ERROR, "中银通前置机未配置");
return E_COMMON_ERR;
}
LOG(DEBUG, "中银通服务器[" << ytc_ip << ":" << ytc_port << "]");
CTcpSocket sock;
alarm(timeout / 1000);
if (!sock.ConnectTcp((char*)ytc_ip.c_str(), ytc_port))
{
alarm(0);
LOG(ERROR, "connect to ytc error");
return E_COMMON_ERR;
}
alarm(0);
// 中银通报文
stringstream ss;
ss << setw(4) << setfill('0') << req.length() << req;
LOG(DEBUG, "中银通报文[" << ss.str() << "]");
if (sock.Send((char*)ss.str().c_str(), ss.str().length()) < (int)ss.str().length())
{
LOG(ERROR, "Send to ytc error");
return E_COMMON_ERR;
}
// 包头
size_t body_len = 0;
{
char buffer[5] = {0};
if (sock.Recv(buffer, 4, timeout) <= 0)
{
LOG(ERROR, "Recv body head from ykc error");
return E_COMMON_ERR;
}
istringstream is(buffer);
is >> body_len;
}
// 包体
string body;
{
char* buffer = new char[body_len + 1];
memset(buffer, 0, body_len + 1);
if (sock.Recv(buffer, body_len, timeout) <= 0)
{
LOG(ERROR, "Recv body from ykc error");
delete [] buffer;
return E_COMMON_ERR;
}
body = buffer;
delete [] buffer;
resp = body;
}
return 0;
}
示例5: F1005
int F1005(TRUSERID *handle,int iRequest,ST_PACK *in_pack,int *pRetCode,char *szMsg)
{
*pRetCode=-1;
ST_CPACK aPack;
CCcbTrans CcbTran(in_pack);
CCcbTrans *pTrans = &CcbTran;
if(!pTrans->AssignReqHead())
{
strcpy(szMsg,pTrans->getErrMsg().c_str());
cout<<szMsg<<endl;
return -1;
}
pTrans->prepare();
if(!pTrans->replaceTemlateVarValue())
{
strcpy(szMsg,pTrans->getErrMsg().c_str());
cout<<szMsg<<endl;
return -1;
}
CTcpSocket tcpSocket;
int ret = -1;
string bankReqData,bankRepData;
if(!pTrans->buildBankRequestData(pTrans->getTemplateData(),bankReqData))
{
strcpy(szMsg,pTrans->getErrMsg().c_str());
cout<<szMsg<<endl;
return -1;
}
if(pTrans->debug)
cout<<"bankReqData : "<<bankReqData<<endl;
if(!tcpSocket.ConnectTcp((char*)pTrans->pBank->getNCService().ip.c_str(),pTrans->pBank->getNCService().port))
{
*pRetCode=9999;
sprintf(szMsg,"连接建设银行IP[%s]Port[%d] 失败",pTrans->pBank->getNCService().ip.c_str(),pTrans->pBank->getNCService().port);
cout<<szMsg<<endl;
writelog(LOG_ERR,szMsg);
return -1;
}
ret = tcpSocket.Send((char*)bankReqData.c_str(),bankReqData.length());
if(ret!=bankReqData.length())
{
*pRetCode=9999;
sprintf(szMsg,"发送数据到建设银行IP[%s]Port[%d] 失败",pTrans->pBank->getNCService().ip.c_str(),pTrans->pBank->getNCService().port);
cout<<szMsg<<endl;
writelog(LOG_ERR,szMsg);
return -1;
}
CCBMSGHEAD ccbMsgHead;
char *pccbMsgHead =(char*) &ccbMsgHead;
ret = tcpSocket.Recv(pccbMsgHead, sizeof(ccbMsgHead), pTrans->pBank->getNCService().timeout*1000);
if(ret<=0)
{
char errBuf[256];
*pRetCode=9999;
tcpSocket.GetLastError(errBuf);
sprintf(szMsg,"从建设银行IP[%s]Port[%d] 接收数据失败,Error: %s\n",pTrans->pBank->getNCService().ip.c_str(),pTrans->pBank->getNCService().port,errBuf);
cout<<szMsg<<endl;
writelog(LOG_ERR,szMsg);
return -1;
}
if(pTrans->debug)
{
cout<<"length: "<< ccbMsgHead.msgDataLen<<"type: " <<ccbMsgHead.commMode<<endl;
cout<<ccbMsgHead.txCode <<" curblock : "<<ccbMsgHead.curBlock<<"totalblock : "<<ccbMsgHead.totalBlock<<endl;
}
int len = atoi(ccbMsgHead.msgDataLen);
char *pRcvBuf=(char*)malloc(len+1);
ret = tcpSocket.Recv(pRcvBuf, len, pTrans->pBank->getNCService().timeout*1000);
if(ret<=0)
{
*pRetCode=9999;
sprintf(szMsg,"从建设银行IP[%s]Port[%d] 接收数据失败",pTrans->pBank->getNCService().ip.c_str(),pTrans->pBank->getNCService().port);
cout<<szMsg<<endl;
writelog(LOG_ERR,szMsg);
return -1;
}
tcpSocket.Close();
pRcvBuf[len] =0;
bankRepData = string(pRcvBuf,len);
if(pTrans->debug)
cout<<"报文: bankRepData:"<<bankRepData<<endl;
free(pRcvBuf);
string fileName;
if(getNodeValByNodeName(bankRepData, "FileName", fileName))
{
string repFile = "ccbRepFile";
fileName.erase(0,fileName.find('\\'));
repFile += fileName;
//.........这里部分代码省略.........
示例6: F1004
int F1004(TRUSERID *handle,int iRequest,ST_PACK *in_pack,int *pRetCode,char *szMsg)
{
int ret=0;
*pRetCode=-1;
ST_CPACK aPack;
CTcpSocket tcpSocket;
CBcomTrans BcomTran(in_pack);
CTrans *pTrans = &BcomTran;
if(!pTrans->AssignReqHead())
{
strcpy(szMsg,pTrans->getErrMsg().c_str());
cout<<szMsg<<endl;
return -1;
}
pTrans->prepare();
if(!pTrans->replaceTemlateVarValue())
{
strcpy(szMsg,pTrans->getErrMsg().c_str());
cout<<szMsg<<endl;
return -1;
}
string signReqData;
if(!pTrans->buildSignData(signReqData))
{
strcpy(szMsg,pTrans->getErrMsg().c_str());
cout<<szMsg<<endl;
return -1;
}
if(pTrans->debug)
cout<<"signReqData: "<<signReqData.c_str()<<endl;
if(!tcpSocket.ConnectTcp((char*)pTrans->pBank->getNCService().ip.c_str(),pTrans->pBank->getNCService().port))
{
*pRetCode=9999;
sprintf(szMsg,"连接交通银行IP[%s]Port[%d] 失败",pTrans->pBank->getNCService().ip.c_str(),pTrans->pBank->getNCService().port);
cout<<szMsg<<endl;
writelog(LOG_ERR,szMsg);
return -1;
}
ret = tcpSocket.Send((char*)signReqData.c_str(),signReqData.length());
if(ret!=signReqData.length())
{
*pRetCode=9999;
sprintf(szMsg,"发送数据到交通银行IP[%s]Port[%d] 失败",pTrans->pBank->getNCService().ip.c_str(),pTrans->pBank->getNCService().port);
cout<<szMsg<<endl;
writelog(LOG_ERR,szMsg);
return -1;
}
char szBufLen[8]="";
int timout=pTrans->pBank->getNCService().timeout*1000;
ret = tcpSocket.Recv(szBufLen, 7, timout);
if(ret<=0)
{
*pRetCode=9999;
sprintf(szMsg,"从交通银行IP[%s]Port[%d] 接收数据失败",pTrans->pBank->getNCService().ip.c_str(),pTrans->pBank->getNCService().port);
cout<<szMsg<<endl;
writelog(LOG_ERR,szMsg);
return -1;
}
if(pTrans->debug)
cout<<"报文长度 : "<<szBufLen<<endl;
int len = atol(szBufLen+1);
char *pRcvBuf=(char*)malloc(len+1);
if(!pRcvBuf)
{
*pRetCode=9999;
sprintf(szMsg,"从交通银行IP[%s]Port[%d] 接收数据失败",pTrans->pBank->getNCService().ip.c_str(),pTrans->pBank->getNCService().port);
cout<<szMsg<<endl;
writelog(LOG_ERR,szMsg);
free(pRcvBuf);
return -1;
}
ret = tcpSocket.Recv(pRcvBuf, len, timout);
if(ret<0)
{
char errBuf[256];
*pRetCode=9999;
tcpSocket.GetLastError(errBuf);
sprintf(szMsg,"从交通银行IP[%s]Port[%d] 接收数据失败,errMsg:[%s]",pTrans->pBank->getNCService().ip.c_str(),pTrans->pBank->getNCService().port,errBuf);
cout<<szMsg<<endl;
writelog(LOG_ERR,szMsg);
free(pRcvBuf);
return -1;
}
tcpSocket.Close();
pRcvBuf[len] = 0;
if(pTrans->debug)
cout<<pRcvBuf<<endl;
string bankVerifyData(pRcvBuf,len);
free(pRcvBuf);
string bankData;
if(!pTrans->parseVerifyBankSignedData(bankVerifyData,bankData))
//.........这里部分代码省略.........
示例7: Bank_Trans
//按照通用接口规范进行封装各自银行的接口
int Bank_Trans(TRUSERID *handle,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
int ret=0;
char host[16]=""; //对方机器的ip
short port = 0;
int timeout = 0;
ST_CPACK aPack;
ST_PACK *out_pack = &(aPack.pack);
CTcpSocket tcpsocket ;
// TRANS_REQ trans_req;
// TRANS_ANS trans_ans;
// memset(&trans_req,0x20,sizeof trans_req); // 先填充上空格
// memset(&trans_ans,0x20,sizeof trans_ans);
ResetNormalCPack(&aPack,0,1);
SetCol(handle,0);
SetCol(handle,F_LVOL1,F_SDATE1,F_SCERT_NO,0);
char buf[256] = " ";
char tmp[8] = "";
des2src(host,rPack->scust_auth); // 银行ip
port=rPack->lvol0; // 银行端口
timeout = rPack->lvol1; // 等待银行超时时间
memset(buf,0x20,sizeof buf); // 填充空格
sprintf(buf,"%04d",REQ_PACK_LEN); // 包体长度
strcpy(buf+4,TRANS_CODE); // 交易码
STRLENCPY(buf+8, rPack->sdate0,8); // 交易日期
STRLENCPY(buf+16, rPack->sholder_ac_no,14); // 一卡通交易参考号
STRLENCPY(buf+30, rPack->sphone,32); // 学工号
STRLENCPY(buf+62, rPack->scust_limit,32); // 姓名
STRLENCPY(buf+94,rPack->scust_auth2,18); // 身份证号
STRLENCPY(buf+112,rPack->scust_limit2,32); // 银行卡号
sprintf(buf+144,"%-17.2f",rPack->damt0); // 交易金额
ret = tcpsocket.ConnectTcp(host, port);
if(!ret)
{
writelog(LOG_ERR,"Connect to bank error,error code is [%d],ip_addr[%s],port[%d] ",ret,host,port);
return E_TRANS_CONNECT;
}
buf[REQ_PACK_LEN+4]=0;
writelog(LOG_INFO,"trans send[%s]",buf);
ret = tcpsocket.Send(buf,REQ_PACK_LEN+4);
if (ret<0)
{
// 发送时,端口有问题,包括被关闭
writelog(LOG_ERR,"Send to bank error,error code is [%d] ",ret);
return E_TRANS_REQUEST;
}
else if(0==ret){
// 不应该出现这种情况
writelog(LOG_ERR,"Send to bank,CTcpSocket.Send should not return this error,error code is[%d]!\n",ret);
return E_TRANS_REQUEST;
}
ret = tcpsocket.Recv(buf, ANS_PACK_LEN+4, timeout);
tcpsocket.Close();
buf[ANS_PACK_LEN+4]=0;
writelog(LOG_INFO,"trans recv[%s],recvlen[%d]",buf,ret);
if (ret!=ANS_PACK_LEN+4)
{
out_pack->lvol1 = -1; //超时 或 接收数据错误 ,后台应向银行发冲正
strcpy(szMsg,"接收银行数据错误");
goto r_ret;
}
memcpy(tmp,buf,4);
if(atoi(tmp) != ANS_PACK_LEN)
{
out_pack->lvol1 = -1; //接收数据错误,后台应向银行发冲正
strcpy(szMsg,"接收银行数据错误");
goto r_ret; // 接收时候出错,或超时
}
memcpy(tmp,buf+20,6);
if(strncmp(tmp,"000000",6)!=0) // 银行端处理错误
{
memcpy(szMsg,buf+26,34);
return E_TRANS_BANK_RECVERR;
}
else
{
out_pack->lvol1 = 1;
memcpy(out_pack->sdate1,buf+12,8); // 银行流水号
memcpy(out_pack->scert_no,buf+26,34); // 银行返回信息
}
writelog(LOG_INFO,"bankretinfo[%s],lvol1[%d]",out_pack->scert_no,out_pack->lvol1);
r_ret:
PutRow(handle,out_pack,pRetCode,szMsg);
return 0;
}
示例8: F250001
int F250001(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
int ret=0;
char host[16]=""; //对方机器的ip
short port=0;
ST_CPACK aPack;
ST_PACK *out_pack = &(aPack.pack);
//char senddata[327]="";
//char rcvdata[327]="";
CTcpSocket tcpsocket ;
ext_phone_trans_t PhoneTrans;
//memset(senddata,0x20,sizeof senddata);
//memset(rcvdata,0x20,sizeof rcvdata);
ResetNormalCPack(&aPack,0,1);
SetCol(handle,0);
SetCol(handle,F_SSECTYPES,0);
des2src(host,rPack->scust_auth);
port=rPack->lvol0;
memset(&PhoneTrans,0,sizeof(PhoneTrans));
memcpy(&PhoneTrans, rPack->ssectypes,127);
memset(PhoneTrans.plugdata,0x20,sizeof(PhoneTrans.plugdata));
memcpy(PhoneTrans.signcheck,gSignCheck,strlen(gSignCheck));
//writelog(LOG_ERR,"package_send=[%s] ",rPack->ssectypes);
writelog(LOG_INFO,"Connect to boss system ip_addr[%s],port[%d] ",host,port);
ret = tcpsocket.ConnectTcp(host, port);
if(!ret)
{
writelog(LOG_ERR,"Connect to boss system error,error code is [%d],ip_addr[%s],port[%d] ",ret,host,port);
*pRetCode=E_MOBILE_TRANS_CONNECT;
goto l_ret;
}
printf("send:[%s]\n",(char*)&PhoneTrans);
ret = tcpsocket.Send((char*)&PhoneTrans,sizeof(PhoneTrans));
if (ret<0)
{
// 发送时,端口有问题,包括被关闭
writelog(LOG_ERR,"Send to boss system error,error code is [%d] ",ret);
*pRetCode=E_MOBILE_TRANS_REQUEST;
goto l_ret;
}
else if(0==ret){
// 不应该出现这种情况
writelog(LOG_ERR,"Send to boss system error,CTcpSocket.Send should not return this error,error code is[%d]!\n",ret);
*pRetCode=E_MOBILE_TRANS_REQUEST;
goto l_ret;
}
memset(&PhoneTrans,0,sizeof(PhoneTrans));
if(rPack->lvol1==1)
{
ret = tcpsocket.Recv((char*)&PhoneTrans, sizeof(PhoneTrans), 15000);
tcpsocket.Close();
if (ret!=327)
{
writelog(LOG_ERR,"Receive from boss system error,error code is [%d] ",ret);
*pRetCode=E_MOBILE_TRANS_TIME_OUT;
goto l_ret; // 接收时候出错,或超时
}
printf("trans recv:[%s]\n",(char*)&PhoneTrans);
// memcpy(out_pack->ssectypes,&PhoneTrans,127);
if(strncmp(PhoneTrans.retnum,"00",2)!=0)
{
if(strncmp(PhoneTrans.retnum,"01",2)==0)
{
writelog(LOG_ERR,"trans error,mac error,ret[%s] ",PhoneTrans.retnum);
*pRetCode=E_MOBILE_CHECK_MAC;
goto l_ret;
}
if(strncmp(PhoneTrans.retnum,"02",2)==0)
{
writelog(LOG_ERR,"trans falied ret[%s] ",PhoneTrans.retnum);
*pRetCode=E_MOBILE_TRANS_FAILURE;
goto l_ret;
}
}
else
{
writelog(LOG_INFO,"trans success ret[%s] ","00");
}
}else{
ret=tcpsocket.Recv((char*)&PhoneTrans, sizeof(PhoneTrans), 15000);
tcpsocket.Close();
if (ret!=327)
{
writelog(LOG_ERR,"Receive from boss system error,error code is [%d] ",ret);
*pRetCode=E_MOBILE_TRANS_TIME_OUT;
goto l_ret; // 接收时候出错,或超时
}
printf("query recv:[%s]\n",(char*)&PhoneTrans);
// memcpy(out_pack->ssectypes,&PhoneTrans,127);
if(strncmp(PhoneTrans.retnum,"00",2)!=0)
{
if(strncmp(PhoneTrans.retnum,"01",2)==0)
//.........这里部分代码省略.........
示例9: doProcess
int doProcess(CTcpSocket &acpsocket)
{
printf("\n doProcess3 \n");
int ret = 0;
int pack_len = 0;
int send_len = 0;
char recv_buf[4096] = "";
char send_buf[4096] = "";
//ret = acpsocket.Recv(recv_buf, HEAD_LEN, g_para.bank_timeout);
//ret = acpsocket.Recv(recv_buf, 2048, g_para.bank_timeout);
//ret = acpsocket.Recv(recv_buf, sizeof(recv_buf), g_para.bank_timeout);
acpsocket.Recv(recv_buf, sizeof(recv_buf), g_para.bank_timeout);
ret=strlen(recv_buf);
printf("\n recv_buf[%s] \n len[%d] ret[%d]\n",recv_buf,strlen(recv_buf),ret);
// if(ret != HEAD_LEN)
// {
// writelog(LOG_ERR,"接收银行数据包头错误\n");
// return -1;
// }
// pack_len = atoi(recv_buf);
// ret = acpsocket.Recv(recv_buf, pack_len, g_para.bank_timeout);
// if(ret != pack_len)
// {
// writelog(LOG_ERR,"接收银行数据包体错误\n");
// return -1;
// }
// recv_buf[pack_len]=0;
writelog(LOG_INFO,"len[%d],recv_buf[%s]\n",ret,recv_buf);
ret = doResponse(recv_buf,strlen(recv_buf),send_buf,send_len);
if(ret)
{
if(ret>0)
return ret;
}
send_buf[send_len]=0;
writelog(LOG_INFO,"len[%d],send_buf[%s]\n",send_len,send_buf);
printf("\n xxxxxxxxxxxxxxxxx \nsend_buf[%s]\nsend_len[%d]\n xxxxxxxxxxxxxxxx\n",send_buf);
ret = acpsocket.Send(send_buf,send_len);
//ret = acpsocket.Send("1234",4);
/*
int ret=0;
int send_len=strlen(send_buf);
char buf[2048]={0};
ret=SockNode->Send(send_buf,send_len);
if (ret<=0)
{
SockNode->Close();
set_msg_log(szMsg,"发送数据至银行出错,错误代码[%d]\n",ret);
return false;
}
*/
if(ret != send_len)
{
writelog(LOG_ERR,"发送数据错误\n");
return -1;
}
return 0;
}