Ejemplo n.º 1
0
        public void test_network_udp_queue_rcv()
        {
            int msg_count = 0;

            DRRCommon.Network.UDPReciverWithTime reciver = new DRRCommon.Network.UDPReciverWithTime(19208);
            reciver.GetSocket().ReceiveBufferSize        = 1024 * 1024 * 30;
            //reciver.QueueHeapCountMax = 1;

            Core.RecordCore core = new Core.RecordCore(new double[] { 0, 0 }, "D:/Data/test", "test", "unit test",
                                                       new System.Collections.Generic.List <System.Net.IPEndPoint>()
            {
                new System.Net.IPEndPoint(IPAddress.Any, 19208)
            });

            reciver.DataRcv_Event += (byte[] rcvBytes, System.Net.IPEndPoint point, System.DateTime time) =>
            {
                msg_count++;
                core.Add(time.TotalSeconds(), point.Address.GetAddressBytes(), (ushort)point.Port, rcvBytes);
            };

            reciver.QueueHeap_Event += (int heapCount) =>
            {
                throw new System.Exception("Heap: " + heapCount);
            };

            reciver.Start();

            Thread.Sleep(20000);

            Assert.AreEqual(600_000, msg_count);
        }
Ejemplo n.º 2
0
        public void test_drr_udp_helper_queue_rcv()
        {
            int msg_count = 0;

            var ret = listen(new byte[] { 0, 0, 0, 0 }, 19208, 1024 * 1024);

            Core.RecordCore core = new Core.RecordCore(new double[] { 0, 0 }, "D:/Data/test", "test", "unit test",
                                                       new System.Collections.Generic.List <System.Net.IPEndPoint>()
            {
                new System.Net.IPEndPoint(IPAddress.Any, 19208)
            });


            ushort size = 0, port = 0;
            double time = 0;

            Stopwatch watch = new Stopwatch();

            watch.Start();

            while (watch.ElapsedMilliseconds < 20000)
            {
                byte[] addr  = new byte[4];
                byte[] bytes = new byte[4096];
                ret = receive(bytes, ref size, addr, ref port, ref time);
                if (ret == -1)
                {
                    Thread.Sleep(1);
                }
                else
                {
                    msg_count++;
                    core.Add(time, addr, port, bytes);
                }
            }

            Assert.AreEqual(600_000, msg_count);
        }
Ejemplo n.º 3
0
        private void Recroder_Button_Start_Click(object sender, RoutedEventArgs e)
        {
            bool start_flag = _recorder == null ? true : false;

            // start
            if (start_flag)
            {
                List <IPEndPoint> points = new List <IPEndPoint>();
                _recivers = new List <UDPReciverWithTime>();
                Recorder_Listen_Item buff = null;
                // Check input
                try
                {
                    foreach (Recorder_Listen_Item item in Recorder_Listen_List.Items)
                    {
                        buff = item;

                        var reciver = new UDPReciverWithTime(item.Point.Get_IPPORT());

                        reciver.GetSocket().ReceiveBufferSize = 30 * 1024 * 1024;
                        reciver.QueueHeapCountMax = 1024;
                        reciver.QueueHeap_Event  += (int heapCount) =>
                        {
                            MessageBox.Show("Out of buffer size! HeapCount: " + heapCount);
                            return(UDPReciverWithTime.QueueClearMode.Cancel);
                        };

                        reciver.DataRcv_Event += (byte[] rcvBytes, IPEndPoint point, DateTime time) =>
                        {
                            _recorder.Add(time.TotalSeconds(), point.Address.GetAddressBytes(), (ushort)point.Port, rcvBytes);
                        };

                        _recivers.Add(reciver);
                        points.Add(item.Point.Get_IPEND());
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Wrong Input!\nCheck the Listen List At " + buff?.Num.Text);
                    Recorder_Stop();
                    return;
                }

                double[] segPara = new double[] { 0, 0 };

                try
                {
                    double split_mb = double.Parse(Recorder_Seg_Size.Text);
                    if (split_mb < 0)
                    {
                        throw new Exception("Wrong Split Size Para!");
                    }

                    double split_time = double.Parse(Recorder_Seg_Time.Text);
                    if (split_time < 0)
                    {
                        throw new Exception("Wrong Split Time Para!");
                    }

                    segPara[0] = split_mb;
                    segPara[1] = split_time;
                }
                catch (Exception ee)
                {
                    MessageBox.Show(ee.Message);
                    Recorder_Stop();
                    return;
                }

                // Initial recorder core
                try
                {
                    _recorder = new Core.RecordCore(segPara, _record_path, Recorder_FileName.Text, Recorder_Notes.Text, points,
                                                    infoHandler: (Core.RecordCore.ReplayInfo info) =>
                    {
                        this.Dispatcher.Invoke(() =>
                        {
                            Recorder_Info.Text = "Pkg_Count: " + info.count
                                                 + " Compress_Rate: " + (info.codedLength * 100.0 / (info.originLength == 0 ? -info.codedLength : info.originLength)).ToString("f2") + "%"
                                                 + "\nPkg_Time: " + info.pkgTime;
                        });
                    });

                    // start at here to avoid the lamda func get a null recorder
                    foreach (var reciver in _recivers)
                    {
                        reciver.Start();
                    }
                }
                catch (Exception ee)
                {
                    MessageBox.Show(ee.Message);
                    Recorder_Stop();
                    return;
                }

                Recorder_Button_Start.Content = "Stop";
            }
            // stop
            else
            {
                Recorder_Stop();

                Recorder_Button_Start.Content = "Start";
            }

            foreach (Recorder_Listen_Item item in Recorder_Listen_List.Items)
            {
                item.IsEnabled = !start_flag;
            }
            Recorder_Button_Add_Listener.IsEnabled = !start_flag;
            Recorder_Button_Path.IsEnabled         = !start_flag;
            Recorder_FileName.IsEnabled            = !start_flag;
            Recorder_Notes.IsEnabled    = !start_flag;
            Recorder_Seg_Size.IsEnabled = !start_flag;
            Recorder_Seg_Time.IsEnabled = !start_flag;
        }
Ejemplo n.º 4
0
 private static void Reciver_DataRcv_Event(byte[] rcvBytes, IPEndPoint point, DateTime time)
 {
     _core.Add(time.TotalSeconds(), point.Address.GetAddressBytes(), (ushort)point.Port, rcvBytes);
 }