当前位置: 首页>>代码示例>>C++>>正文


C++ SocketClient::SendToHost方法代码示例

本文整理汇总了C++中SocketClient::SendToHost方法的典型用法代码示例。如果您正苦于以下问题:C++ SocketClient::SendToHost方法的具体用法?C++ SocketClient::SendToHost怎么用?C++ SocketClient::SendToHost使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SocketClient的用法示例。


在下文中一共展示了SocketClient::SendToHost方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: DoSendAndRcv

/**< 跟第三方系统进行通信 */
int CTradeBase::DoSendAndRcv(unsigned char *ReqBuf, int ReqLen,unsigned char *RepBuf, int *RepLen, int TimeOut,char* errDesc)
{
    trace_log(DBG, "SndBuf len:%d",ReqLen);
    trace_mem(ReqBuf, ReqLen);
    SocketClient client;
    return client.SendToHost(ReqBuf,ReqLen,RepBuf,*RepLen,g_Cfg.CupHost.cIp,g_Cfg.CupHost.iPort,40,errDesc);
}
开发者ID:vagabond1132,项目名称:Code,代码行数:8,代码来源:tradebase.cpp

示例2: DoSendAndRcv

/**< 跟第三方系统进行通信 */
int CTradeBase::DoSendAndRcv(unsigned char *ReqBuf, int ReqLen,unsigned char *RepBuf, int *RepLen, int TimeOut,char* errDesc)
{
    trace_log(DBG, "SndBuf len:%d",ReqLen);
    trace_mem(ReqBuf, ReqLen);
#ifndef USE_LONG_CONN
    SocketClient client;
    return client.SendToHost(ReqBuf,ReqLen,RepBuf,*RepLen,g_Cfg.CupHost[0].Host,g_Cfg.CupHost[0].Port,40,errDesc);
#else
	return 0;
#endif
}
开发者ID:vagabond1132,项目名称:Code,代码行数:12,代码来源:tradebase.cpp

示例3: GetDataFromHsm

/**************************************************************
函数名称: GetDataFromHsm
函数功能: 连接加密机从其获取数据
入口参数: pMsgBuffer[in/out]:发送或返回的数据中的MSG
           iLen[in/out]:发送或返回数据的长度
相关调用:
返 回 值: true成功, false失败
**************************************************************/
bool EnCryptComm::GetDataFromHsm(unsigned char *pMsgBuffer, unsigned & iLen)
{
    unsigned char cmd = pMsgBuffer[0], Buffer[1024]={0};
    unsigned sLen;//发送数据长度
    sLen = iLen + 7;
    memcpy(Buffer, &sLen, 2);//LC
    Buffer[2]=0xF1;//INS
    Buffer[3]=0;//SEQ
    //CR默认为0
    memcpy(&Buffer[6], pMsgBuffer, iLen);//MSG
    Buffer[sLen-1] = CalcSum(Buffer, sLen - 1);//CRC
    char errDesc[512]={0};
    unsigned char cRecBuf[1024]={0};
    int recLen=0;
    SocketClient client;
    int iErrorCode=client.SendToHost(Buffer,sLen,cRecBuf,recLen,g_Cfg.EncHost.Host, g_Cfg.EncHost.Port,20,errDesc);
    if(0==iErrorCode)
    {
    	trace_log(DBG, "recv from enchost");
		trace_mem(cRecBuf, recLen);
        if(cRecBuf[recLen-1] == CalcSum(cRecBuf, recLen - 1) && cRecBuf[6] == cmd && cRecBuf[8] == CMD_OK)
        {//校验值正确,与原命令字相同,返回码为成功
            if(memcmp(pMsgBuffer+2, cRecBuf+9, LEN_MERCHNO+LEN_TERMINO)!=0)//+LEN_TERMINO
            {//比较商户号与终端号
                trace_log(DBG, "The return data from encryptor is not match!!");
                return false;
            }
            memcpy(pMsgBuffer, cRecBuf+6, recLen-7);//去掉LC,INS,SEQ,CR,CRC
            iLen = recLen-7;
            trace_log(DBG,"GetDataFromHsm->iLen=%d",iLen);
            return true;
        }
        else
        {
            trace_log(ERR, "GetDataFromHsm else CalcSum  %d", recLen);
            return false ;
        }
    }else{
        trace_log(ERR,errDesc);
        return false;
    }
}
开发者ID:vagabond1132,项目名称:Code,代码行数:50,代码来源:encryptcomm.cpp

示例4: DoTrade

int CTradegetmainkey::DoTrade(SAConnection *saConn, void * pNode)
{

    if(saConn == NULL || pNode == NULL)
    {
        trace_log(ERR, "Paramter error!");
        return RET_SYSEXP;
    }
    trace_log(DBG,"-----getmainkey-----");
    /********************pack********************/
    TRADEDATA * pData = (TRADEDATA *)pNode;

    int iFieldDataLen = 0;
    bool bFlag = true;
    BYTE bFieldData[64] = {0};
    BYTE bKeyData[200] = {0};
    trace_log(DBG,"pack 8583");

    TRADEDATA pTmpData;
    memcpy(&pTmpData, pData, sizeof(TRADEDATA));
    pTmpData.TransData.HeadData.RTradeType = POS_GETMAINKEY;
    pTmpData.TransData.HeadData.nLFlowID = 0;

    CUPS8583 sndObj;
    //0消息类型
    bFlag &= sndObj.SetValueByStr(0, "0820");
	 //41	受卡机终端标识码
    bFlag &= sndObj.SetValueByStr(41, pTmpData.TransData.HeadData.arrRTermNo);

    //42	受卡方标识码
    bFlag &= sndObj.SetValueByStr(42, pTmpData.TransData.HeadData.arrRMerchNo);
    //60	自定义域
    memcpy(bFieldData,"00",2);
	strcat((char *)bFieldData,(char *)pData->BatchNo);
	strcat((char *)bFieldData,(char *)"102");
    bFlag &= sndObj.SetValueByStr(60, (char *)bFieldData);
    //62域 秘钥信息
    /*BYTE fieldData62[120]={0};
    memset(fieldData62,20,15);//ip地址
    strcat((char *)fieldData62,"00000000000000000000");//sim卡号
    strcat((char *)fieldData62,"0000.00.00");
    strcat((char *)fieldData62,"0000.00.00");
    strcat((char *)fieldData62,"460");
    strcat((char *)fieldData62,"00");
    strcat((char *)fieldData62,"0000");
    strcat((char *)fieldData62,"0000");
    strcat((char *)fieldData62,"00000000000000000000000000000000");*/

    /*rsa_init(&rsa,RSA_PKCS_V15, 0 );
    rsa_gen_key(&rsa,NULL,NULL,1024,65537);
    rsa_public(&rsa,KLK,bFieldData);*/
    bFlag &=sndObj.SetValueByHex(62,bFieldData,100);
   /**< 插入交易记录 */
    if(COperateDB::MyBeforeInsertDB(saConn, &pTmpData))
    {
        trace_log(ERR, "MyBeforeInsertDB(getmainkey) return failed!");
        return 	RET_SYSEXP;
    }

    /**< 打包 */
    unsigned char SndBuf[PACK_MAXLEN]={0};
    unsigned iSndLen = sizeof(SndBuf);
    bFlag &= sndObj.Pack(SndBuf, iSndLen);
    if(!bFlag)
    {
        trace_log(ERR, "Pack right CUPS8583 fail!");
        return RET_PACK;
    }

    SetMsgHead(SndBuf, iSndLen, pData);/**<  设置报文头*/
    /********************communication********************/
    unsigned char RcvBuf[PACK_MAXLEN]={0};
    int iRcvLen = sizeof(RcvBuf);
    trace_log(DBG,"getmainkey SndBuf len:",iSndLen);
    trace_mem(SndBuf,iSndLen);
    char errDesc[512]={0};
    SocketClient client;
    if(0 !=  client.SendToHost(SndBuf,(int)iSndLen,RcvBuf,iRcvLen,g_Cfg.CupHost[0].Host,(int)g_Cfg.CupHost[0].Port,60000,errDesc))
    {
        trace_log(ERR, errDesc);
        return RET_SYSEXP;
    }
    /********************unpack********************/
	trace_log(DBG,"RcvBuf len:",iRcvLen);
    trace_mem(RcvBuf,iRcvLen);
    CUPS8583 rcvObj;
    if(1 != rcvObj.UnPack(RcvBuf, iRcvLen))
    {
        trace_log(ERR, "unpack right CUPS8583 error!");
        return RET_UNPACK;
    }

    iFieldDataLen = rcvObj.GetValueByStr(39, pTmpData.TransData.HeadData.RspCode,
                                          sizeof(pTmpData.TransData.HeadData.RspCode));
    if(iFieldDataLen != 2)
    {
        trace_log(ERR, "GetValueByStr fail!(Field39)");
        return RET_MSGERR;
    }
    if(memcmp(pTmpData.TransData.HeadData.RspCode,"00",2)==0)
//.........这里部分代码省略.........
开发者ID:vagabond1132,项目名称:Code,代码行数:101,代码来源:tradegetmainkey.cpp

示例5: DoTrade


//.........这里部分代码省略.........
	 //41	受卡机终端标识码
    bFlag &= sndObj.SetValueByStr(41, pTmpData.TransData.HeadData.arrRTermNo);

    //42	受卡方标识码
    bFlag &= sndObj.SetValueByStr(42, pTmpData.TransData.HeadData.arrRMerchNo);
	
    //60	自定义域
    memcpy(bFieldData,"00",2);
	strcat((char *)bFieldData,(char *)pData->BatchNo);
	strcat((char *)bFieldData,(char *)"003");
    bFlag &= sndObj.SetValueByStr(60, (char *)bFieldData);
	//63	自定义域
	bFlag &= sndObj.SetValueByStr(63, (char *)"001");


    /**< 打包 */
    unsigned char SndBuf[PACK_MAXLEN]={0};
    unsigned iSndLen = sizeof(SndBuf);
    bFlag &= sndObj.Pack(SndBuf, iSndLen);
    if(!bFlag)
    {
        trace_log(ERR, "Pack right CUPS8583 fail!");
        return RET_PACK;
    }

    SetMsgHead(SndBuf, iSndLen, pData);/**<  设置报文头*/
    /********************communication********************/
    unsigned char RcvBuf[PACK_MAXLEN]={0};
    int iRcvLen = sizeof(RcvBuf);
    trace_log(DBG,"login SndBuf len:%d",iSndLen);
    trace_mem(SndBuf,iSndLen);
    char errDesc[512]={0};
    SocketClient client;
	trace_log(DBG,"SendToHost:%s:%d",g_Cfg.CupHost.cIp, g_Cfg.CupHost.iPort);
    if(0 !=  client.SendToHost(SndBuf,(int)iSndLen,RcvBuf,iRcvLen,g_Cfg.CupHost.cIp,(int)g_Cfg.CupHost.iPort,60000,errDesc))
    {
        trace_log(ERR, errDesc);
        return RET_SYSEXP;
    }
    /********************unpack********************/
	trace_log(DBG,"RcvBuf len:",iRcvLen);
    trace_mem(RcvBuf,iRcvLen);
    CUPS8583 rcvObj;
    if(1 != rcvObj.UnPack(RcvBuf, iRcvLen))
    {
        trace_log(ERR, "unpack right CUPS8583 error!");
        return RET_UNPACK;
    }

    memset(bFieldData, 0, sizeof(bFieldData));
    iFieldDataLen = rcvObj.GetValueByStr(13, (char*)bFieldData, sizeof(bFieldData));
    if(iFieldDataLen <= 0)
    {
        trace_log(ERR, "GetValueByStr failed!(Field13)");
        return RET_MSGERR;
    }

    iFieldDataLen = rcvObj.GetValueByStr(39, pTmpData.TransData.HeadData.RspCode,
                                          sizeof(pTmpData.TransData.HeadData.RspCode));
    if(iFieldDataLen != 2)
    {
        trace_log(ERR, "GetValueByStr fail!(Field39)");
        return RET_MSGERR;
    }
    if(memcmp(pTmpData.TransData.HeadData.RspCode,"00",2)==0)
    {
开发者ID:vagabond1132,项目名称:Code,代码行数:67,代码来源:tradelogin.cpp


注:本文中的SocketClient::SendToHost方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。