我用socket::Receive(pbuffer,bufferSize);接收数据,但是对方发送的是16进制数,
其中有一个是0x00,我接收不到0x00以后的数据,因为我的pbuffer遇到0x00以为数组结束了,取数组长度得到的结果是0x00以前的元素个数,这种情况怎么解决?怎么能够得到全部数据呢?谢谢

解决方案 »

  1.   

    不能根据buffer取长度,recv函数会返回实际接收字节数的.
    你要看看你这个socket::Receive(pbuffer,bufferSize);的源码是如何处理的,bufferSize是否返回实际接收长度---
    recv
    The Windows Sockets recv function receives data from a connected socket.int recv(
      SOCKET s,       
      char FAR *buf,  
      int len,        
      int flags       
    );
    Parameters

    [in] Descriptor identifying a connected socket. 
    buf 
    [out] Buffer for the incoming data. 
    len 
    [in] Length of buf. 
    flags 
    [in] Flag specifying the way in which the call is made. 
    Return Values
    If no error occurs, recv returns the number of bytes received. If the connection has been gracefully closed, the return value is zero. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError.
      

  2.   

    谢谢xiao_fang(frank) 对了!!