示例#1
0
        public void Start(IPEndPoint traceEP, IPAddress traceAdapter, NetTraceSinkDelegate onReceive)
        {
            lock (syncLock)
            {
                sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
                sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1);
                sock.Bind(new IPEndPoint(traceAdapter, traceEP.Port));

                if (traceAdapter.Equals(IPAddress.Any))
                {
                    sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(traceEP.Address));
                }
                else
                {
                    sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership,
                                         new MulticastOption(traceEP.Address, traceAdapter));
                }

                sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, 5);
                sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastLoopback, 1);

                this.onReceive  = onReceive;
                this.recvBuf    = new byte[NetTracePacket.MaxPacket];
                this.recvEP     = new IPEndPoint(IPAddress.Any, 0);
                this.onSockRecv = new AsyncCallback(OnSockReceive);
                this.recvQueue  = new Queue(10000);
                this.timer      = new GatedTimer(new TimerCallback(OnTimer), null, TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(0.5));

                sock.BeginReceiveFrom(recvBuf, 0, recvBuf.Length, SocketFlags.None, ref recvEP, onSockRecv, null);
            }
        }
示例#2
0
        public static void Start(NetTraceSinkDelegate onReceive)
        {
            lock (syncLock)
            {
                IPEndPoint traceEP;
                IPAddress  traceAdapter;
                Config     config;

                config       = new Config("Diagnostics");
                traceEP      = config.Get("TraceEP", new IPEndPoint(Helper.ParseIPAddress(NetTrace.DefTraceGroup), NetTrace.DefTracePort));
                traceAdapter = config.Get("TraceAdapter", IPAddress.Any);

                if (traceSink != null)
                {
                    traceSink.Stop(null);
                    traceSink = null;
                }

                traceSink = new NetTraceSink();
                traceSink.Start(traceEP, traceAdapter, onReceive);
            }
        }
示例#3
0
        /// <summary>
        /// Called on form load.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void MainForm_Load(object sender, System.EventArgs args)
        {
            DataColumnCollection  dtColumns;
            DataGridTableStyle    dgStyle;
            DataGridTextBoxColumn col;

            // Initialize the data table and set

            dtCapture = new DataTable("capture");
            dtColumns = dtCapture.Columns;
            dtColumns.Add("Time", typeof(DateTime));
            dtColumns.Add("SourceEP", typeof(string));
            dtColumns.Add("Event", typeof(string));
            dtColumns.Add("Summary", typeof(string));
            dtColumns.Add("Details", typeof(string));

            // Bind these to the trace grid

            TraceList.DataSource = dtCapture;

            // Configure the grid columns

            dgStyle              = new DataGridTableStyle();
            dgStyle.MappingName  = dtCapture.TableName;
            dgStyle.ReadOnly     = true;
            dgStyle.AllowSorting = false;

            // Time

            col             = new DataGridTextBoxColumn();
            col.Alignment   = HorizontalAlignment.Center;
            col.HeaderText  = "Time (UTC)";
            col.MappingName = "Time";
            col.NullText    = string.Empty;
            col.ReadOnly    = true;
            col.Width       = 100;
            col.Format      = "HH:mm:ss.fff";
            dgStyle.GridColumnStyles.Add(col);

            // SourceEP

            col             = new DataGridTextBoxColumn();
            col.Alignment   = HorizontalAlignment.Center;
            col.HeaderText  = "SourceEP";
            col.MappingName = "SourceEP";
            col.NullText    = string.Empty;
            col.ReadOnly    = true;
            col.Width       = 75;
            dgStyle.GridColumnStyles.Add(col);

            // Event

            col             = new DataGridTextBoxColumn();
            col.Alignment   = HorizontalAlignment.Left;
            col.HeaderText  = "Event";
            col.MappingName = "Event";
            col.NullText    = string.Empty;
            col.ReadOnly    = true;
            col.Width       = 225;
            dgStyle.GridColumnStyles.Add(col);

            // Summary

            col             = new DataGridTextBoxColumn();
            col.Alignment   = HorizontalAlignment.Left;
            col.HeaderText  = "Summary";
            col.MappingName = "Summary";
            col.NullText    = string.Empty;
            col.ReadOnly    = true;
            col.Width       = 1600;
            dgStyle.GridColumnStyles.Add(col);

            // Details (hidden)

            col             = new DataGridTextBoxColumn();
            col.Alignment   = HorizontalAlignment.Left;
            col.HeaderText  = "Details";
            col.MappingName = "Details";
            col.NullText    = string.Empty;
            col.ReadOnly    = true;
            col.Width       = 0;
            dgStyle.GridColumnStyles.Add(col);

            TraceList.TableStyles.Clear();
            TraceList.TableStyles.Add(dgStyle);

            // Complete the initialization

            isRunning     = true;
            captureFile   = false;
            captureWriter = null;
            SetUIState();

            onTraceUI = new NetTraceSinkDelegate(OnTraceUI);
            NetTraceSink.Start(new NetTraceSinkDelegate(OnTrace));

#if SIMPACKETS
            NetTrace.Start();
            timer = new GatedTimer(new TimerCallback(OnTimer), null, TimeSpan.FromTicks(0), TimeSpan.FromSeconds(5.0));
#endif
        }