private void SendReceive()
        {
            while (this.data_out.Count > 0)
            {
                UdpItem item = this.data_out.Peek();

                try
                {
                    int size = this.Sock.SendTo(item.Data, item.EndPoint);

                    if (size == item.Data.Length)
                    {
                        this.data_out.Dequeue();
                        UdpStats.Record(item.Msg);
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
                catch
                {
                    if (item.Attempts++ > 2)
                    {
                        this.data_out.Dequeue();
                    }
                }
            }

            EndPoint ep = new IPEndPoint(IPAddress.Any, 0);

            byte[] buffer = new byte[8192];

            while (this.Pending)
            {
                try
                {
                    int size = this.Sock.ReceiveFrom(buffer, ref ep);

                    if (size > 0)
                    {
                        UdpItem item = new UdpItem();
                        item.Msg      = (UdpMsg)buffer[0];
                        item.Data     = buffer.Skip(1).Take(size).ToArray();
                        item.EndPoint = ep;
                        this.data_in.Enqueue(item);
                    }
                }
                catch { break; }
            }
        }
        public void Start()
        {
            UdpStats.Reset();
            UdpNodeManager.Initialize();

            this.TcpTester.PopulateNodes();
            this.Showing          = Settings.Get <bool>("udp");
            this.Timer_1_Second   = Time.Now;
            this.Timer_1_Minute   = Time.Now;
            this.Timer_15_Minutes = Time.Now;
            this.Sock             = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            this.Sock.Blocking    = false;
            this.Sock.Bind(this.EndPoint);
        }
        public void ServiceUdp(ulong time)
        {
            this.SendReceive();

            while (this.data_in.Count > 0)
            {
                try
                {
                    UdpProcessor.Eval(this.data_in.Dequeue(), this, time);
                }
                catch { }
            }

            if ((this.Timer_1_Second + 1000) < time)
            {
                this.Timer_1_Second = time;
                this.firewall_tests.ForEachWhere(x => x.Stop(), x => (x.Time + 10000) < time);
                this.firewall_tests.RemoveAll(x => x.Completed);

                if (this.TcpTester.IsTesting)
                {
                    this.TcpTester.TestNext(this);
                }
                else if (this.Showing)
                {
                    this.Push(time);
                }
            }

            if ((this.Timer_1_Minute + 60000) < time)
            {
                this.Timer_1_Minute = time;
                this.TcpTester.Timeout();
                UdpNodeManager.Expire(time);
            }

            if ((this.Timer_15_Minutes + 900000) < time)
            {
                this.Timer_15_Minutes = time;
                UdpNodeManager.Update(time);
                ServerCore.Log("local node list updated [" + UdpStats.SENDINFO + ":" + UdpStats.ACKINFO + ":" + UdpStats.ADDIPS + ":" + UdpStats.ACKIPS + "]");
                UdpStats.Reset();
            }
        }