如何清除WinSock中的接收缓冲区

发布于 2024-09-24 11:44:40 字数 263 浏览 6 评论 0原文

我去寻找这个问题,发现至少有一个人提出了这个问题,但没有得到答案。我认为需要启动发送和接收段(同一套接字连接上较大进程的一部分)并期望接收缓冲区中已经没有任何内容。

我没有看到答案,但在我自己意识到另一种看起来更干净的方法之前确实想到了这个拼凑(读到下一段的“结尾”)。只需将 RecieveTimeout 设置为 1,或者,如果您认为发送方仍在发送过程中,则设置一些稍大的值。然后只需使用 socketflags = 0 调用 Receive 并丢弃结果。

有人有更好的方法吗?

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 connection) 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

君勿笑 2024-10-01 11:44:40

这个要求的由来是什么?您真的需要丢弃数据吗?

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

一曲爱恨情仇 2024-10-01 11:44:40

我当时以为我这样做了,但后来只是读取并缓存了结果,然后从缓存中删除了。我正在搜索发送命令时出现的不同结果序列(字符串)。发送的下一个命令不能假设接收缓冲区中不再有任何字符,因为协议“标准”指定响应可能以 CR 或 LF 或 CRLF 或 LFCR 或什么都没有结束。由于该协议的定义非常松散,因此不同的组织以不同的方式实现该协议。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文