CSocketFile,CSocket,CArchive写的聊天室,服务器端OnReceive收不到消息?
本帖最后由 oyljerry 于 2011-05-30 17:52:46 编辑 问题如上,我是学习田大新的vc视频,模仿制作的,但是客户端发来的消息,就是接收不到,奇怪!
客户端代码:
消息序列化函数
void CMsg::Serilize(CArchive &ar)
{
if(ar.IsStoring())
{
ar<<code;
ar<<(WORD)m_bClose;
ar<<m_strText;
}
else
{
ar>>(UINT)code;
WORD wd;
ar>>wd;
m_bClose = (BOOL)wd;
ar>>m_strText;
}
}
发送消息函数:
void CChatClientDoc::SendMsg(CString &strText, int mCode, BOOL bSendName)
{
if(m_pArchiveOut!=NULL)
{
CMsg msg;
msg.code = mCode;
msg.m_strText=(bSendName?m_strName+_T(":")+strText:strText);
TRY
{
msg.Serialize(*m_pArchiveOut);//我跟踪执行到了这里。
m_pArchiveOut->Flush();
}
CATCH(CFileException,e)
{
m_pArchiveOut->Abort();
delete m_pArchiveOut;
m_pArchiveOut = NULL;
CString strTemp;
strTemp.Format("发送失败");
DisplayMsg(strTemp);
}
END_CATCH
}
}
服务器端代码
//这段代码总是不响应
void CClientSocket::OnReceive(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
CSocket::OnReceive(nErrorCode);
m_pDoc->ProccssReceive(this);
}