简体   繁体   English

定时记录和重放UDP数据包

[英]Record and replay UDP packets with timing

I need to implement a way of recording an UDP stream with the purpose of later on replaying that stream as requested. 我需要实现一种记录UDP流的方法,以便稍后根据请求重播该流。 This record and replay must use the same timing (up to a sensible resolution, hardly perceivable by a human user, let's say 10ms): if the original stream had data for seconds 00:00 to 00:35, then went mute till 00:55, and then sent more data from 00:55 to 01:34, the same distribution must be observed when my application replays that stream. 记录和重播必须使用相同的时间(达到合理的分辨率,几乎不被人类用户感知,比如说10毫秒):如果原始流中的数据是从00:00到00:35的几秒钟,则静音直到00: 55,然后从00:55到01:34发送更多数据,当我的应用程序重放该流时,必须观察到相同的分布。

If it were just a matter of saving the udp stream to disk and then replaying it, without this timing, it would be trivial by either using Socket, NetworkStream or UdpClient. 如果只是将udp流保存到磁盘上,然后在没有此定时的情况下重播它,那么使用Socket,NetworkStream或UdpClient都是微不足道的。 The issue is I cannot get around to devise a way to modify the standard receive algorithm to include that timing in a way that it's somehow easily replayed later by the send algorithm. 问题是我无法解决一种修改标准接收算法的方法,以使其包含时序的方式,以便稍后可以通过send算法轻松地重播该时序。 As a bonus, a way to start the replay at any time mark (from 00:15 on, for example) should also be supported. 另外,还应该支持一种在任何时间标记(例如,从00:15开始)开始重播的方法。

1) Is there any way to easily implement this functionality on C#? 1)有什么方法可以轻松地在C#上实现此功能? We do not have any severe non-functional requirement for this, we just need for it to simply work. 我们对此没有任何严重的非功能性要求,我们只需要它简单地工作即可。 Any hint about a way to implement it would be really appreciated. 任何有关实现它的方式的提示将不胜感激。

2) If this is indeed not a simple matter and anyone suggests the use of any third-party component for this, the requirements would be for it to have an API for C# (or a way to operate the component from code), and hopefully be opensource or freely used software. 2)如果这确实不是一件简单的事情,并且有人建议为此使用任何第三方组件,那么要求是拥有一个C#API(或一种通过代码操作该组件的方法),并且希望是开源或免费使用的软件。

Thank you very much. 非常感谢你。

This is not exactly a native feature of C#. 这并不是C#的本机功能。 But I will attempt to do your homework. 但是我会尽力做你的作业。

The way I would attack this is still to store the packets to disk. 我要攻击的方法仍然是将数据包存储到磁盘。 Design a custom file structure in binary format, Holding data about the time the Datagram was recieved followed by the UDP Datagram itself. 设计一个二进制格式的自定义文件结构,保存有关数据报接收时间的数据,然后是UDP数据报本身。 You can then have a program read this file back, Find out at what time the UDPs payload was delivered. 然后,您可以让一个程序读回该文件,找出UDP负载在何时交付。 This will give you what you need to replay the packets and store it for later replay with all native C# Code, no third party modules. 这将为您提供重放数据包并将其存储以供以后使用所有本机C#代码(无第三方模块)重放所需的内容。 This will of course require you to know writing to/from a file and being able to parse the relevant data into the typed objects in C# (Timespan, maybe byte[] for the Datagram, etc). 当然,这将需要您知道写入文件或从文件写入文件,并能够将相关数据解析为C#中的类型化对象(时间跨度,对于数据报来说可能为byte []等)。 All of these decisions would be up to you, the program writer. 所有这些决定都取决于程序编写者。

The long and the short of it is i'm 99% certain there's no native functionality for this kind of requirement. 总而言之,我99%肯定没有这种要求的本机功能。 This is exactly Why programming languages exist. 这正是编程语言存在的原因。 So we as programmers can produce amazing solutions for our clients/customers/Teachers ;) 因此,我们作为程序员可以为我们的客户/客户/老师提供出色的解决方案;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM