为什么即使进程在本地运行,我也会让 UDP 数据报乱序?

2022-01-22 00:00:00 udp java datagram

我正在开发流媒体服务器和 Flash 客户端之间的 Java 接口.我注意到即使两个进程都在本地运行,UDP 数据报也可以无序地到达我的接口.

I'm developing a java interface between a streaming server and a flash client. I noticed that UDP datagrams can reach my interface out of order even if both processes are running locally.

这正常吗?我认为由于没有数据报必须通过任何路由器或任何网络设备,所以不应该发生这种情况.

Is that normal? I thought that as no datagram has to go through any router or any network device, then that should not be happening.

推荐答案

实际上,UDP 数据包的排序和接收并不能保证,即使它们是由 localhost 在 localhost 上发送的.只是因为协议的规范并不暗示它.

Actually there are no guarantees of ordering and reception about UDP packets, even if they are sent by localhost on localhost. Just because the specification of the protocol doesn't imply anything about it.

由于您无法对它们做出假设,因此您应该选择使用 TCP 或使用程序处理的序列号来处理重新排序.

Since you can't make assumptions on them you should choose to use TCP or handle reordering by using a sequence number handled by your programs..

相关文章