David G.Brazales
David G.Brazales

Reputation: 9

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. 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.

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. 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. As a bonus, a way to start the replay at any time mark (from 00:15 on, for example) should also be supported.

1) Is there any way to easily implement this functionality on 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.

Thank you very much.

Upvotes: 0

Views: 710

Answers (1)

Skintkingle
Skintkingle

Reputation: 1579

This is not exactly a native feature of 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. You can then have a program read this file back, Find out at what time the UDPs payload was delivered. 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. 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). 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. This is exactly Why programming languages exist. So we as programmers can produce amazing solutions for our clients/customers/Teachers ;)

Upvotes: 2

Related Questions