SendBytesNow() public method

public SendBytesNow ( byte Data, int Length ) : bool
Data byte
Length int
return bool
        public void SendBytesNow_LoopBack_SequenceNumber16K()
        {
            int i;
            bool result = false;

            UDPSender us = new UDPSender("127.0.0.1", 7770);

            byte[] data = new byte[1024 * 16];

            for (i = 0; i < data.Length; i++)
            {
                data[i] = (byte)i;
            }

            UdpClient listener = new UdpClient(7770);
            IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, 7770);

            //Blocking Call
            us.SendBytesNow(data, 1024 * 16);

            //BLOCKING CALL
            byte[] bytes = listener.Receive(ref groupEP);

            for (i = 0; i < data.Length; i++)
            {
                if (bytes[i] != (byte)i)
                {
                    Assert.True(false);
                }
            }

            Assert.True(true);

            listener.Close();
        }
Example #2
0
        public void BitmapAcquiredCBHandler(Bitmap aNewBitmap)
        {
            byte[] newBA  = aCodecUtility.CompressBmpToJPEGArray(aImageQuality, aNewBitmap);
            int    FileID = aRandomGenerator.Next();

            //Total size of the packet to send including header  +  data.
            PacketPartitionner pp = new PacketPartitionner(FileID, newBA.Length, Packet.GetHeaderSize() + Packet.DEFAULT_PACKET_SIZE, null);

            pp.PartitionFile(newBA, newBA.Length);

            //Console.WriteLine("Partition File ID " + FileID + " In " + pp.GetPartitionnedPackets().Count + " Packets");

            //Remove prints to the console
            for (int i = 0; i < pp.GetPartitionnedPackets().Count; i++)
            {
                Packet p = ((Packet)(pp.GetPartitionnedPackets()[i]));

                //Console.WriteLine("Send Packet:"+i);

                byte[] SerializedPacket = p.GetBytes();

                //Sending the data to a blocking queue that gets process by a thread generate additionnal delay
                //The best solution to reduce the lag for now is to send the data directly with SendNow method.
                //aUDPSender.SendDataUDP(SerializedPacket, SerializedPacket.Length);

                aUDPSender.SendBytesNow(SerializedPacket, SerializedPacket.Length);
            }

            pp.GetPartitionnedPackets().Clear();
        }
        public void SendBytesNow_LoopBack1k()
        {
            UDPSender us = new UDPSender("127.0.0.1", 7778);

            byte[] data = new byte[1024 *1];

            UdpClient listener = new UdpClient(7778);
            IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, 7778);

            //Blocking Call
            us.SendBytesNow(data, 1024 * 1);

            //BLOCKING CALL
            byte[] bytes = listener.Receive(ref groupEP);

            Assert.AreEqual(us.GetTotalNbDataINOUT(), bytes.Length);

            listener.Close();
        }
        public void SendBytesNow_TestWith4K()
        {
            UDPSender us = new UDPSender("127.0.0.1", 7777);

            byte[] data = new byte[1024 * 4];

            us.SendBytesNow(data, 1024 * 4);

            Assert.AreEqual(us.GetTotalNbDataINOUT(), 1024 * 4);
        }
        public void SendBytesNow_TestWith10M_BufferOverflow()
        {
            UDPSender us = new UDPSender("127.0.0.1", 7777);

            byte[] data = new byte[1024 *1024 *10];

            us.SendBytesNow(data, 1024*1024*10);

            Assert.AreEqual(us.GetTotalNbDataINOUT(),0);
        }