Exemple #1
0
        static void InitialReciver(string ip, int port, ref List <IPEndPoint> points)
        {
            var point   = new IPandPort(ip, port);
            var reciver = new UDPReciverWithTime(point);

            _recivers.Add(reciver);

            reciver.GetSocket().ReceiveBufferSize = 1024 * 1024;
            reciver.QueueHeapCountMax = 1024;
            reciver.QueueHeap_Event  += Reciver_QueueHeap_Event;

            reciver.DataRcv_Event += Reciver_DataRcv_Event;

            points.Add(new IPEndPoint(IPAddress.Parse(ip), port));

            Logger.Info.WriteLine("Initial Reciver Success! Listen On " + ip + ":" + port);
        }
Exemple #2
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;
        }