急问!!!MFC中用 CSocket和 Archive进行通讯的问题.
server能够收到Client发送的字符串,但是server发送的确认Client没有任何反应.
CMsg类是从CObject类派生的,用于基于CArchive的数据发送和接受,定义如下;
class CMsg : public CObject
{
protected:
DECLARE_DYNCREATE(CMsg)
public:
CMsg();
// Attributes
public:
CString m_strText;
BOOL m_bClose;
CStringList m_msgList;
// Operations
public:
void Init();
// Implementation
public:
virtual ~CMsg();
virtual void Serialize(CArchive& ar);
}
CMsg的Serialize函数:
void CMsg::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
ar << (WORD)m_bClose;
ar << m_strText;
}
else
{
WORD wd;
ar >> wd;
m_bClose = (BOOL)wd;
ar >> m_strText;
}
m_msgList.Serialize(ar);
}
client 端的CClientSocket类从CSocket类派生,用于和server的通讯:
class CTestDlg;
class CClientSocket : public CSocket
{
DECLARE_DYNAMIC(CClientSocket);
// Attributes
public:
CTestDlg* m_pDlg;
// Operations
public:
CClientSocket(CTestDlg* pDlg);
virtual ~CClientSocket();
// Overrides
public:
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CClientSocket)
//}}AFX_VIRTUAL
// Generated message map functions
//{{AFX_MSG(CClientSocket)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
// Implementation
protected:
virtual void OnRecieve(int nErrorCode);
};
其中OnRecieve函数如下:
void CClientSocket::OnRecieve(int nErrorCode)
{
CSocket::OnReceive(nErrorCode);
m_pDlg->ProcessPendingMsg();
}
server的确认
/*CMsg msg;
msg.Init();
CString temp="ok!";
msg.m_strText=temp;
SendMsg(pSocket,&msg);*/
请问是怎么回事,如何解决?