问题如下,我从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);
}

解决方案 »

  1.   

    int nLen = this->Receive ( buf, MAX_PACK_LEN);   this->Send(sendbuf,512);
      

  2.   

    我把我截到的包发到下面。收到:   2B 47 2F 35 30 31 2F 33 31-30                 此处应该有一个 ACK 回应包,但是事实上没有,就直接发送了下面的数据发送:   39 3F 75 5A 75 75 45 5B 76-76 76 67 75 76 76 66 75
      

  3.   

    http://www.vckbase.com/code/downcode.asp?id=2594
      

  4.   

    goodheart你好,你给的代码是用的 recv() 函数接收数据的,跟我这不太一样啊。
      

  5.   

    void CMyAsyncSocket::OnReceive(int nErrorCode)   // CMyAsyncSocket is 
                                                    // 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里面什么都有,包括例子
      

  6.   

    多谢上面各位的帮助,我在 Send() 之前加了一个 Sleep() 就解决了,现在给分。