CAsyncSocket的Receive可以接收
如:Receive(buf,size,0);
这个的size可能是1000,但是Receive返回值有可能没接收到1000这么多。
---------------------------------------------------------------------
那CAsyncSocket的Send呢?
Send(buf,size,0);
这个的size是1000,那Send的返回值,也就是发出的长度一定是1000吗?
前题是buf一定大于1000这个长度。
----------------------------------------------------------------------
是否可以细说说。谢谢了。很急。

解决方案 »

  1.   

    Send的返回值总是<= size,不可能大于它
      

  2.   

    CAsyncSocket的Send,一般来讲是等于设置的长度,除非长度太长超过了socket的缓冲区尺寸(默认为8192),或者是发生了错误。
      

  3.   

    size就以1000为限度。那Send返回的值,一定是1000吗?
    不会产生小于1000的时候吗?
    谢谢各位。
      

  4.   

    会小1000。Send返回的值是跟网络状况有关的。
      

  5.   

    CAsyncSocket的Send在什么情况下会返回小于设定的size?
    谢谢。很急
      

  6.   

    补充 sans(sans) 兄弟:我用winsock编写的send都超过了8192字节,有10M多,默认确实8192字节,但是接受方的缓冲区如果够大的,比如有10K,像我那样就可以接收10M,100k可以接收30多M。当然那时候发送方也成功发送。实际上发送和接收的多少是看send和receive的返回值,同时像 Bind(天高云淡) 说的那样:
    Send的返回值总是<= size,不可能大于它
      

  7.   

    不是在什么情况下,是肯定小于设定的size
    呵呵,如果你缓冲区只有1000,你怎么会一次发送大于它的东西,发送数据是要先把数据放在缓冲区上的
      

  8.   

    看返回值
    see MSDN Sample:
    // 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);
    }
    if (dwBytes>=0) 就是每次send的字节数
    if (dwBytes = -1)就有错误(除WSAEWOULDBLOCK 发送缓冲满)