public void UdpMediumDataTest() { var sender = new DataChunker(MaxDatagramSize); var data64KB = RandomData(0xFFFF); var chunks = GetChunks(1, data64KB, sender); VerifyReceive(data64KB, chunks, 2, true, 1, 0); }
public void UdpInterleavedDatagramsTest() { var sender = new DataChunker(MaxDatagramSize); var chunksA = GetChunks(1, RandomData(0xFFFFF), sender).ToArray(); var chunksB = GetChunks(2, RandomData(0xFFFFF), sender).ToArray(); var interleaved = chunksA.Zip(chunksB, (a, b) => new byte[][] { a, b }).SelectMany(_ => _).ToArray(); VerifyReceive(null, interleaved, 34, false, 34, 33); // 34 starts/restarts, 33 abandoned, last set incomplete }
public void UdpDroppedDatagramsTest() { var data1MB = RandomData(0xFFFFF); var data2KB = RandomData(0xFFF); var sender = new DataChunker(MaxDatagramSize); var chunks = GetChunks(2, data1MB, sender).ToList(); chunks.RemoveAt(7); // drop! var concat = chunks.Concat(GetChunks(3, data2KB, sender)); // then send a different set, abandons and completes instead VerifyReceive(data2KB, concat, 17, true, 2, 1); // receives 2 chunks + 1 abandoned set }
/// <summary> /// Convert payload data chunked into a list of datagrams. /// </summary> /// <param name="id">Message ID.</param> /// <param name="data">Payload bytes.</param> /// <param name="sender">UdpChunkSender instance.</param> /// <returns>List of datagrams.</returns> private static IEnumerable <byte[]> GetChunks(int id, byte[] data, DataChunker sender) { return(sender.GetChunks(id, data, data.Length).Select(chunk => chunk.Item1.Take(chunk.Item2).ToArray())); }