C#中:如何处理乱序的TCP数据包? [英] C#: How to deal with out-of-order TCP packets?

查看:111
本文介绍了C#中:如何处理乱序的TCP数据包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

能否取悦别人解释这个现象如何处理乱序包。我使用原始套接字捕获数据包,并分析他们,因为他们来了,但他们中的一些进来顺序错误,例如:

Can please someone one explain how to deal with out-of-order packets. I'm using raw socket to capture packets, and parse them as they come, but some of them come in wrong order, for example:


  1. 标识标志...........

  2. 16390:(PSH,ACK)

  3. 16535:(PSH,ACK)

  4. 16638:(ACK)

  5. 16640:(PSH,ACK)

  6. 16639:(ACK)

  7. 16695:(PSH,ACK)

  1. Id...........Flags
  2. 16390 : (PSH, ACK)
  3. 16535 : (PSH, ACK)
  4. 16638 : (ACK)
  5. 16640 : (PSH, ACK)
  6. 16639 : (ACK)
  7. 16695 : (PSH, ACK)

与ID的数据包:16390,16535,16695是独立的包,可以加工任意
的报文用的ID:16638,16640,16639是数据包的序列,应该把升序解析之前。

Packets with IDs: 16390, 16535, 16695 are separate packets and can be processed freely Packets with IDs: 16638, 16640, 16639 are a sequence of packets and should be put in ascending order before parsing.

要使其与PUSH标志更糟糕的分组有时略同,所以我只是通过他们对分析器,然后将该preceds谈到和解析器只是丢弃它作为损坏的数据包。

To make it worse packets with Push flag sometimes come first so I just pass them along to parser, and then packet that preceds it comes and parser just discards it as corrupted.

有什么办法来对付它?

推荐答案

TCP保证秩序。所以,我只是假设你正在谈论IP。

TCP guarantees order. So I will just assume you are talking about IP.

有一件事你可以尝试是把在一个最小堆的数据包,然后等待,直到下一个数据包的ID号,你希望是可用的。

One thing you could try is putting the packets in a min-heap and then waiting until the next packet ID number you want is available.

至于推包,这些都应该是不会对排序的限制,尽快收到,所以它的你来决定多久要等待,看看您会收到较早推文。

As for the push packets, those are supposed to be received as soon as possible without a restriction on ordering, so its up to you to decide how long you want to wait to see if you'll receive an earlier push packet.

这篇关于C#中:如何处理乱序的TCP数据包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆