本文整理汇总了C++中CBaseSocket::SendMsg方法的典型用法代码示例。如果您正苦于以下问题:C++ CBaseSocket::SendMsg方法的具体用法?C++ CBaseSocket::SendMsg怎么用?C++ CBaseSocket::SendMsg使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBaseSocket
的用法示例。
在下文中一共展示了CBaseSocket::SendMsg方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SendXmlToPhone
int CCommunication::SendXmlToPhone(CString argRequest, CString& argResponse,FunctionSocketCallBack CallBack,bool IsSetOutTime)
{
// argRequest = ReplaceStr( argRequest, _T("&"), _T("&") ); // zhaoshan [2012.01.11]
// argRequest = ReplaceStr( argRequest, _T("<"), _T("<") ); // zhaoshan [2012.02.27]
//argRequest = ReplaceStr(argRequest, _T("&"), _T("&") ); // zhaoshan [2012.01.11]
// argRequest = ReplaceStr( argRequest, _T("\""), _T(""") );
// argRequest = ReplaceStr( argRequest, _T("\'"), _T("' ") );
CString FunName=GetRequestFuncationName(argRequest);
if(CCommunication::m_nExceptionHeart > 0x03)
{
XWriteEventLog(_T("[CCommunication::SendXmlToPhone] %s CCommunication::ExceptionHeart > 0x02.\r\n"),FunName);
return -1;
}
//建立连接
CString strShowInfo;
argResponse.Empty();
CBaseSocket OclsBSocket ;
CBaseSocket* clsBSocket = &OclsBSocket;
//CBaseSocket* clsBSocket = CBaseSocket::GetInstance();
if(NULL == clsBSocket)
{
XWriteEventLog(_T("[CCommunication::SendXmlToPhone] CBaseSocket::GetInstance Failed.\r\n"));
m_nExceptionCounter++;
return -1;
}
int nRet = -1;
SOCKET sendSocket;
nRet = clsBSocket->InitializeAndCreateSocket(&sendSocket,IsSetOutTime);
if(0x00 != nRet)
{
nRet = GetLastError();
strShowInfo.Format(_T("[CCommunication::SendXmlToPhone] InitializeAndCreateSocket ErrorNo=[%d].\r\n"), nRet);
XWriteEventLog(strShowInfo);
clsBSocket->CloseSocket( &sendSocket);
return -2;
}
nRet = clsBSocket->ConnectToServer(&sendSocket, CCommunication::m_Port, CCommunication::m_Ip);
if(0x00 != nRet)
{
nRet = GetLastError();
strShowInfo.Format(_T("[CCommunication::SendXmlToPhone] FunName=[%s] ConnectToServer ErrorNo=[%d].\r\n"),FunName, nRet);
XWriteEventLog(strShowInfo);
m_nExceptionCounter++;
clsBSocket->CloseSocket( &sendSocket);
if( 10061 == nRet)
{
return -33;
}
return -3;
}
//发送命令
if( ! argRequest.IsEmpty())
{
nRet = clsBSocket->SendMsg(&sendSocket, argRequest);
if(0x00 != nRet)
{
int iRevLen=-4;
nRet = GetLastError();
::XWriteEventLog(_T("[CCommunication::SendXmlToPhone] %s Request Error=[%d]\n"),FunName,nRet);
if(nRet == 10060)
iRevLen=-6; //Socket 超时返回值
clsBSocket->CloseSocket( &sendSocket);
return iRevLen;
}
}else
{
XWriteEventLog(_T("[CCommunication::SendXmlToPhone] argRequest is Empty.\r\n"));
return -5;
}
//接收返回值
argResponse = "";
clsBSocket->RecvMsg(&sendSocket,argResponse,CallBack);
return argResponse.GetLength();
}
示例2: GetLastError
int CCommunication::CheckHeart4PhoneS2(CBaseSocket & ttBSocket , SOCKET & sendSocket, CString argRequest, CString& argResponse)
{
//////////////////////////////////////////////////////////////////////
int nRet = 0;
CString strShowInfo;
//发送命令
if( ! argRequest.IsEmpty())
{
//nRet = ttBSocket.SetCallFuncName(CCommunication::m_strCallFuncName);
nRet = ttBSocket.SendMsg(&sendSocket, argRequest);
if(0x00 != nRet)
{
nRet = GetLastError();
strShowInfo.Format(_T("[CCommunication::CheckHeart4PhoneS2] SendMsg ErrorNo=[%d].\r\n"), nRet);
XWriteEventLog(strShowInfo);
m_nExceptionHeart++;
//ttBSocket.CloseSocket( &sendSocket);
return -4;
}
}else
{
XWriteEventLog(_T("[CCommunication::CheckHeart4PhoneS2] argRequest is Empty.\r\n"));
return -5;
}
//接收返回值
argResponse = "";
BYTE pRevStrTmp[1024 + 1] = {0};
int dword=0, iRevLen = 0;
Sleep(200);
do
{
memset(pRevStrTmp, 0x00, sizeof(pRevStrTmp));
dword = ttBSocket.RecvMsg( &sendSocket, pRevStrTmp, 1024);
if(dword > 0x00 )
{
argResponse += (CHAR*)pRevStrTmp;
iRevLen += dword;
/// 接收完成 CheckHeart4Phone
if((-1) != argResponse.Find(_T("</res>"))) dword = 0x00;
}else
{
Sleep(200);
}
}while( dword != SOCKET_ERROR && dword != 0);
if(SOCKET_ERROR != dword)
{
m_bPhoneStatus = TRUE;
}else
{
iRevLen = dword;
m_nExceptionHeart++;
nRet = GetLastError();
strShowInfo.Format(_T("[CCommunication::CheckHeart4PhoneS2] ErrorNo=[%d].\r\n"), nRet);
XWriteEventLog(strShowInfo);
}
if(argResponse.IsEmpty())
{
strShowInfo.Format(_T("[CCommunication::CheckHeart4PhoneS2] Resp Data is Empty.\r\n"));
XWriteEventLog(strShowInfo);
}
//CString strAckEnd = _T("===ack===");
//nRet = ttBSocket.SendMsg(&sendSocket, strAckEnd);
return iRevLen;
}