Example #1
0
        public void TestResendsAfterLosingAcks()
        {
            Cdp.TryStaticInit(Cdp.MaxPayloadWithIDOverUdp);

            IPEndPoint        serverEndPoint = new IPEndPoint(IPAddress.Loopback, testUdpPort);
            FixedRetryTimeout timeout        = new FixedRetryTimeout(100, 6);

            using (TestServerWrapper server = new TestServerWrapper(serverEndPoint, timeout))
            {
                Cdp.TryStaticInit(Cdp.MaxPayloadWithIDOverUdp);

                //
                //
                //
                UdpConnectedClientTransmitter udpTransmitter    = new UdpConnectedClientTransmitter(serverEndPoint);
                ClumsyTransmitter             clumsyTransmitter = new ClumsyTransmitter(udpTransmitter, Console.Out);
                CdpTransmitter transmitter = new CdpTransmitter(clumsyTransmitter);

                Int64 startTicks = Stopwatch.GetTimestamp();
                Console.WriteLine("[Sender {0} millis] Sending...", (Stopwatch.GetTimestamp() - startTicks).StopwatchTicksAsInt64Milliseconds());

                UInt32 offset;
                Byte[] datagram = transmitter.RequestSendBuffer(10, out offset);
                for (Byte i = 0; i < 10; i++)
                {
                    datagram[offset++] = (Byte)('A' + i);
                }
                clumsyTransmitter.DropAllReceivedDatagramsForTheNext(400);
                transmitter.ControllerSendPayloadWithAck(offset, timeout);
                server.TestSucceeded();
            }
        }
Example #2
0
        public void TestMethod1()
        {
            Cdp.TryStaticInit(Cdp.MaxPayloadWithIDOverUdp);

            IPEndPoint        serverEndPoint = new IPEndPoint(IPAddress.Loopback, testUdpPort);
            FixedRetryTimeout timeout        = new FixedRetryTimeout(500, 6);

            using (TestServerWrapper server = new TestServerWrapper(serverEndPoint, timeout))
            {
                UdpConnectedClientTransmitter udpTransmitter = new UdpConnectedClientTransmitter(serverEndPoint);
                CdpTransmitter transmitter = new CdpTransmitter(udpTransmitter);


                UInt32 offset;
                Byte[] myMessage;
                Byte[] payloadBuffer;


                //
                // Send and wait for ack
                //
                myMessage = Encoding.UTF8.GetBytes("This should be a normal payload with an immediate ack");

                payloadBuffer = transmitter.RequestSendBuffer((UInt32)myMessage.Length, out offset);
                Array.Copy(myMessage, 0, payloadBuffer, offset, myMessage.Length);
                offset += (UInt32)myMessage.Length;
                Console.WriteLine("[Client] Sending Payload With Ack...");
                transmitter.ControllerSendPayloadWithAck(offset, timeout);

                //
                // Send heartbeat
                //
                Console.WriteLine("[Client] Sending Heartbeat...");
                transmitter.SendHearbeat();

                //
                // Send Random Payload
                //
                myMessage = Encoding.UTF8.GetBytes("This should be a random payload");

                payloadBuffer = transmitter.RequestSendBuffer((UInt32)myMessage.Length, out offset);
                Array.Copy(myMessage, 0, payloadBuffer, offset, myMessage.Length);
                offset += (UInt32)myMessage.Length;
                Console.WriteLine("[Client] Sending Random Payload...");
                transmitter.ControllerSendRandomPayload(offset);

                //
                // Send Payload no ack
                //
                myMessage = Encoding.UTF8.GetBytes("This should be the first payload with no immediate ack");

                payloadBuffer = transmitter.RequestSendBuffer((UInt32)myMessage.Length, out offset);
                Array.Copy(myMessage, 0, payloadBuffer, offset, myMessage.Length);
                offset += (UInt32)myMessage.Length;
                Console.WriteLine("[Client] Sending Payload No Ack...");
                transmitter.ControllerSendPayloadNoAck(offset);

                //
                // Send Payload no ack
                //
                myMessage = Encoding.UTF8.GetBytes("This should be the second payload with no immediate ack");

                payloadBuffer = transmitter.RequestSendBuffer((UInt32)myMessage.Length, out offset);
                Array.Copy(myMessage, 0, payloadBuffer, offset, myMessage.Length);
                offset += (UInt32)myMessage.Length;
                Console.WriteLine("[Client] Sending Payload No Ack...");
                transmitter.ControllerSendPayloadNoAck(offset);

                //
                // Send and wait for ack
                //
                myMessage = Encoding.UTF8.GetBytes("This should be a normal payload with an immediate ack");

                payloadBuffer = transmitter.RequestSendBuffer((UInt32)myMessage.Length, out offset);
                Array.Copy(myMessage, 0, payloadBuffer, offset, myMessage.Length);
                offset += (UInt32)myMessage.Length;
                Console.WriteLine("[Client] Sending Payload With Ack...");
                transmitter.ControllerSendPayloadWithAck(offset, timeout);

                //
                // Send Halt
                //
                Console.WriteLine("[Client] Sending Halt...");
                transmitter.SendHaltNoPayload();

                server.TestSucceeded();
                Console.WriteLine("[Client] Done (Success)");
            }
        }