예제 #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);
        }
예제 #2
0
        private void Recorder_Stop()
        {
            if (_recivers != null)
            {
                foreach (var reciver in _recivers)
                {
                    reciver.Stop();
                }
            }

            _recorder?.WriteComplete();
            _recorder = null;
        }
예제 #3
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);
        }
예제 #4
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;
        }
예제 #5
0
        static void LoadPara(string[] args)
        {
            if (args.Length % 2 != 0)
            {
                Logger.Error.WriteLine("Para Input Error!");
                return;
            }

            Dictionary <string, string> para = new Dictionary <string, string>();

            for (int i = 0; i < args.Length; i += 2)
            {
                para.Add(args[i], args[i + 1]);
            }

            List <IPEndPoint> points = new List <IPEndPoint>();

            if (para.ContainsKey("-l"))
            {
                var pp = para["-l"].Split(" ");

                foreach (var item in pp)
                {
                    var    p    = item.Split(":");
                    string ip   = "";
                    int    port = 0;
                    // 仅指定 port
                    if (p.Length == 1)
                    {
                        ip = "0.0.0.0";
                    }
                    // 指定 ip 与 port
                    else if (p.Length == 2)
                    {
                        ip   = p[0];
                        p[0] = p[1];
                    }
                    else
                    {
                        Logger.Error.WriteLine("Wrong Reciver Para!");
                    }

                    try
                    {
                        port = int.Parse(p[0]);
                    }
                    catch (Exception)
                    {
                        Logger.Error.WriteLine("Wrong Reciver Port!");
                        return;
                    }

                    InitialReciver(ip, port, ref points);
                }
            }
            else
            {
                Logger.Error.WriteLine("No Reciver Para!");
                return;
            }

            double[] segPara = new double[] { 2048, 3600 };
            if (para.ContainsKey("-s"))
            {
                var ss = para["-s"].Split(" ");
                try
                {
                    segPara[0] = double.Parse(ss[0]);
                    segPara[1] = double.Parse(ss[1]);
                }
                catch (Exception)
                {
                    Logger.Error.WriteLine("Wrong SegMentPara!");
                    return;
                }
            }

            double indexInterval = 1;

            if (para.ContainsKey("-i"))
            {
                try
                {
                    indexInterval = double.Parse(para["-i"]);
                }
                catch (Exception)
                {
                    Logger.Error.WriteLine("Wrong IndexInterval!");
                    return;
                }
            }

            string notes = "";

            if (para.ContainsKey("-n"))
            {
                notes = para["-n"];
            }


            string path = "data/";
            string name = DateTime.UtcNow.ToString("yyyy-MM-dd_HH-mm-ss");

            if (para.ContainsKey("-p"))
            {
                path = para["-p"];
            }
            if (para.ContainsKey("-f"))
            {
                if (para["-f"].Contains("/"))
                {
                    Logger.Error.WriteLine("File name can not contains '/'!");
                    return;
                }
                else
                {
                    name = para["-f"];
                }
            }

            Core.RecordCore.DeleInfoHandler infoHandler = (Core.RecordCore.ReplayInfo info) =>
            {
                Console.WriteLine("Pkg_Count: " + info.count
                                  + " Compress_Rate: " + (info.codedLength * 100.0 / (info.originLength == 0 ? -info.codedLength : info.originLength)).ToString("f2") + "%"
                                  + " Pkg_Time: " + info.pkgTime);
            };

            _core = new Core.RecordCore(segPara, path, name, notes, points, infoHandler: infoHandler);

            // 保证在 core 实例化之后
            // 否则回调函数里的 core 会为 null
            foreach (var rec in _recivers)
            {
                rec.Start();
            }
        }