开发者

How do you clear the receive buffer in WinSock

开发者 https://www.devze.com 2023-01-17 20:06 出处:网络
I went searching for this and found at least one person who asked but got no answer. I think there is a need to start a send and receive segment (part of a larger process on same socket connect开发者_

I went searching for this and found at least one person who asked but got no answer. I think there is a need to start a send and receive segment (part of a larger process on same socket connect开发者_Go百科ion) and expect that there is nothing already in the receive buffer.

I saw no answer but did think of this kludge before I myself realized another way around it that seemed cleaner (read to "ends with" on the next segment). Simply set the RecieveTimeout to 1 or, if you think the sender is still in the process of sending, some slightly larger value. Then just call Receive with socketflags = 0 and discard the results.

Does anyone have a better way?


What is the origin of this requirement? Do you really have a need to throw data away?


I thought I did at the time but then just read and cached the results and then removed from cache instead. I'm searching for different result sequences (strings) that come about when sending a command. The next command sent can't assume that there are no longer any chars in the receive buffer since the protocol "standard" specifies that a response may end with a CR or LF or CRLF or LFCR or nothing. This protocol is implemented differently by different organizations since it is so loosely defined.

0

精彩评论

暂无评论...
验证码 换一张
取 消