XP 上 C# 中的 UDP 缓冲区

发布于 2024-10-21 12:48:19 字数 170 浏览 2 评论 0原文

我有一个连续的 udp 数据包流到运行 Windows XP 的计算机。 在某个时刻,我启动一个侦听器(用 C# 编写)来处理收到的 udp 数据包。

当我启动侦听器时,我是否会收到由于缓冲区而在侦听器启动之前发送的数据包,或者我是否可以确定进入侦听器的第一个数据包实际上是自侦听器启动以来收到的第一个数据包?

I have a continuous stream of udp packets to a computer running windows xp.
At some point I start a listener (written in C#) that handles the udp packets received.

When I start the listener, will I get packets that were sent before the listener was started due to a buffer, or can I be certain that the first packet I get into my listener is actually the first packet received since the listener was started?

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

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

发布评论

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

评论(1

小耗子 2024-10-28 12:48:19

UDP 传送不保证按顺序到达、完全到达、仅到达一次或在特定时间后到达

因此,您还需要处理在开始侦听端口之前发送的 UDP 数据包,但由于某种原因进行了一次世界巡演,直到之后才到达> 你开始倾听。

在大多数操作系统实现中,当 UDP 数据包到达某个端口(并且不是广播)并且没有人侦听该端口上的 UDP 时,该数据包将被丢弃。但是,UDP 数据包有可能到达操作系统并在网络驱动程序的内部缓冲区中排队, 在侦听器启动时操作系统有机会处理它之前。然后你也会看到它。

一般来说,永远不要假设 UDP 数据包有任何可靠的信息。

UDP delivery is not guaranteed to arrive in order, to arrive at all, to arrive only once, or to arrive after a certain time.

Therefore, you'll need to also handle UDP packets that have been sent before you started listening to the port, but for some reason took a world tour and did not arrive until after you started listening.

In most O/S implementations, when a UDP packet arrives to a port (and it is not broadcast) and there is no one listening on UDP on that port, the packet gets discarded. However, there is a chance that a UDP packet arrives at the O/S and gets queued in the network driver's internal buffer, before the O/S has a chance to process it when your listener starts. Then you'll also see it.

In general, never assume anything reliable to come from UDP packets.

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