问题如下,我从CSocket继承了一个 CMySocket 类,重载了 OnReceive 函数,然后在里面加了一个send 函数,正常情况下,Receive ()函数执行过后应该会回应一个ACK包以确认接收到了数据,而我用截包程序却发现在Send()函数执行之前没有回应ACK包,请问是怎么回事,部分代码如下,请高手救命!!!#define MAX_PACK_LEN 65535 // IP 数据包的最大长度class CMySocket : public CSocket
{
public:
CMySocket ();
virtual ~CMySocket (); char sendbuf[512];
virtual void OnReceive(int nErrorCode);
};void CMySocket::OnReceive(int nErrorCode)
{
char buf[MAX_PACK_LEN];
int nLen = CSocket::Receive ( buf, MAX_PACK_LEN); CSocket.Send(sendbuf,512); CSocket::OnReceive(nErrorCode);
}
{
public:
CMySocket ();
virtual ~CMySocket (); char sendbuf[512];
virtual void OnReceive(int nErrorCode);
};void CMySocket::OnReceive(int nErrorCode)
{
char buf[MAX_PACK_LEN];
int nLen = CSocket::Receive ( buf, MAX_PACK_LEN); CSocket.Send(sendbuf,512); CSocket::OnReceive(nErrorCode);
}
// derived from CAsyncSocket
{
static int i=0; i++; TCHAR buff[4096];
int nRead;
nRead = Receive(buff, 4096);
switch (nRead)
{
case 0:
Close();
break;
case SOCKET_ERROR:
if (GetLastError() != WSAEWOULDBLOCK)
{
AfxMessageBox ("Error occurred");
Close();
}
break;
default:
buff[nRead] = 0; //terminate the string
CString szTemp(buff);
m_strRecv += szTemp; // m_strRecv is a CString declared
// in CMyAsyncSocket
if (szTemp.CompareNoCase("bye") == 0 ) ShutDown();
}
CAsyncSocket::OnReceive(nErrorCode);
}/////////////////////////////////////////////////////////////////// CMyAsyncSocket is derived from CAsyncSocket and defines the
// following variables:
// CString m_sendBuffer; //for async send
// int m_nBytesSent;
// int m_nBytesBufferSize;void CMyAsyncSocket ::OnSend(int nErrorCode)
{
while (m_nBytesSent < m_nBytesBufferSize)
{
int dwBytes; if ((dwBytes = Send((LPCTSTR)m_sendBuffer + m_nBytesSent,
m_nBytesBufferSize - m_nBytesSent)) == SOCKET_ERROR)
{
if (GetLastError() == WSAEWOULDBLOCK) break;
else
{
TCHAR szError[256];
wsprintf(szError, "Server Socket failed to send: %d",
GetLastError());
Close();
AfxMessageBox (szError);
}
}
else
{
m_nBytesSent += dwBytes;
}
}
if (m_nBytesSent == m_nBytesBufferSize)
{
m_nBytesSent = m_nBytesBufferSize = 0;
m_sendBuffer = "";
}
CAsyncSocket::OnSend(nErrorCode);
}
你看了就明白了,MSDN里面什么都有,包括例子