如果客户端发了10个字节,服务器先读取5个字节,然后再读取五个字节.
问题是为什么读取了5个字节后再去读,发现剩下的5个字节没有了?
这是什么原因呢?难道一次只能读完,读不完就丢失了?还是有个时间限制,多长时间后就消息了
谢谢

解决方案 »

  1.   

    If the datagram or message is larger than the buffer supplied, the buffer is filled with the first part of the datagram and recv generates the error WSAEMSGSIZE. 
    For unreliable protocols (for example, UDP), the excess data is lost; 
    for reliable protocols, the data is retained by the service provider until it is successfully read by calling recv with a large enough buffer. 以上是MSDN对recv函数的解释,大体意思是:对于不可靠协议(如UDP),超出的部分将会被丢掉;而对于TCP则不会,数据会一直保存到被用户读完为止。所以你的程序是不是使用UDP协议啊?
      

  2.   

    TCP是流,UDP是数据报,后者发过去不管你怎么处理,也不管是否发送到达