在使用设个函数发送数据的时候,数据发送的频率较快,譬如我发送了10次数据这时WSASend也执行
了10次,但是监控网络上的数据的时候发现发出的数据是8次,其中有两次的数据是两个数据包累叠
而成的,大概是缓冲区的问题,但是关闭缓冲区会降低性能,又没有其他的方法可以解决这个问题
吗?使得能够正确的发送数据.

解决方案 »

  1.   

    Scatter-Gather I/O
    Scatter-gather support is a concept originally introduced in Berkeley Sockets with the functions recv and writev. This feature is available with the Winsock 2 functions WSARecv, WSARecvFrom, WSASend, and WSASendTo. It is most useful for applications that send and receive data that is formatted in a very specific way. For example, messages from a client to a server might always be composed of a fixed 32-byte header specifying some operation, followed by a 64-byte data block and terminated with a 16-byte trailer. In this example, WSASend can be called with an array of three WSABUF structures, each corresponding to the three message types. On the receiving end, WSARecv is called with three WSABUF structures, each containing data buffers of 32 bytes, 64 bytes, and 16 bytes.When using stream-based sockets, scatter-gather operations simply treat the supplied data buffers in the WSABUF structures as one contiguous buffer. Also, the receive call might return before all buffers are full. On message-based sockets, each call to a receive operation receives a single message up to the buffer size supplied. If the buffer space is insufficient, the call fails with WSAEMSGSIZE and the data is truncated to fit the available space. Of course, with protocols that support partial messages, the MSG_PARTIAL flag can be used to prevent data loss.
      

  2.   

    这就是TCP的流stream啊,没有边界。
      

  3.   


    d fdff
    流stream就会产生粘包的问题
      

  4.   

    这要什么解决的办法?这就是TCP的流的概念。你自己得处理记录边界的问题。例如搞个固定的包头,里面有长度等。
      

  5.   

    但是客户端接收使用单片机,flash非常有限,不可能使用太大的缓冲区