📄 msnsocket.cpp
字号:
// MsnSocket.cpp : implementation file
//
#include "stdafx.h"
#include "SimMsnMessenger.h"
#include "MsnSocket.h"
#include "MsnLoginClient.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMsnSocket
CMsnSocket::CMsnSocket()
{
}
CMsnSocket::CMsnSocket(CMsnLoginClient *pClient)
{
m_pClient = pClient;
m_pFile = NULL;
m_pArchiveIn = NULL;
m_pArchiveOut = NULL;
}
CMsnSocket::~CMsnSocket()
{
}
// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CMsnSocket, CSocket)
//{{AFX_MSG_MAP(CMsnSocket)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif // 0
/////////////////////////////////////////////////////////////////////////////
// CMsnSocket member functions
void CMsnSocket::OnReceive(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
char bufRecv[2048];
//char bufTem[512];
int iTem;
int iLen;
int iStart, iEnd;
char cTem;
CString strTem1,strTem2;
int i;
do
{
iLen = this->Receive( bufRecv, 2047 );
if( iLen <=0 )
{
FileLog("<-Reveive %04d bytes:<span style=\"background-color: #0000FF\">[ERROR!!]</span>", iLen);
return;
}
if (iLen >= 2047 ) iLen = 2047;
bufRecv[iLen] = 0x00;
if( iLen < 80 ) FileLog("<-Reveive %04d bytes::<span style=\"background-color: #669999\">[%s]</span>", iLen , bufRecv);
else FileLog("<-Reveive %04d bytes::<span style=\"background-color: #669999\">[<br>%s]</span>", iLen , bufRecv);
if(m_pClient != NULL)
{
//process the recved Message:
iStart = iEnd = 0;
cTem = bufRecv[0];
strTem1 = CString(bufRecv);
i = 0;
iTem = strTem1.GetLength();
for(;iEnd < iTem;)
{
iEnd = strTem1.Find(_T("\r\n")); //?? CR LF?
if(iEnd == -1)
{
FileLog("Not Find CR LF ! Error!");
iEnd = strTem1.GetLength();
}
strTem2 = strTem1.Mid(0,iEnd);
m_pClient->m_iBytesForCmd=0;
m_pClient->ParseRecvedStr(strTem2);
if( m_pClient->m_iBytesForCmd > 0 )
{
FileLog("!!应当调用相关方法处理数据 Len=[%d]",m_pClient->m_iBytesForCmd);
iEnd=iEnd+m_pClient->m_iBytesForCmd;
}
iTem = strTem1.GetLength();
if(iEnd+2 >= iTem) break;
strTem1 = strTem1.Mid(iEnd+2,iTem);
i++;
}
}
} while(!this->m_pArchiveIn->IsBufferEmpty());
CSocket::OnReceive(nErrorCode);
}
//DEL void CMsnSocket::OnSend(int nErrorCode)
//DEL {
//DEL // TODO: Add your specialized code here and/or call the base class
//DEL FileLog("->发送OnSend: nErrorCode=[%d]", nErrorCode);
//DEL CSocket::OnSend(nErrorCode);
//DEL }
int CMsnSocket::Send(const void* lpBuf, int nBufLen, int nFlags)
{
// TODO: Add your specialized code here and/or call the base class
// TODO: Add your specialized code here and/or call the base class
FileLog("->Send %04d bytes::<span style=\"background-color: #CC6600\">[%s]</span>", nBufLen , lpBuf);
return CSocket::Send(lpBuf, nBufLen, nFlags);
}
void CMsnSocket::OnClose(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
FileLog("<-MSN Server 主动关闭连接 CMsnSocket::OnClose(nErrorCode=%d)", nErrorCode);
CSocket::OnClose(nErrorCode);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -