Пример #1
0
        protected void PingCallback(object sender, System.Net.NetworkInformation.PingCompletedEventArgs e)
        {
            // If the operation was canceled, display a message to the user.
            if (e.Cancelled)
            {
                Console.WriteLine("Ping canceled.");
                Disconnect(((ClientConnection)e.UserState).ThisID);
            }

            // If an error occurred, display the exception to the user.
            if (e.Error != null)
            {
                Console.WriteLine("Ping failed:");
                Disconnect(((ClientConnection)e.UserState).ThisID);
            }

            System.Net.NetworkInformation.PingReply reply = e.Reply;
            int id = ((int)e.UserState);

            Clients[id].Ping = (int)(reply.RoundtripTime / 2);
            PacketDesc_Ping pkt = new PacketDesc_Ping();

            pkt.PacketTarget         = EConnectionType.CLIENT;
            pkt.PacketOriginClientID = UniqueID;
            pkt.ToServerLatency      = Clients[id].Ping; // send clients one way to server latency
            SendPacketToClient(pkt, id);
        }
Пример #2
0
        private void Ping_Complete(object sender, System.Net.NetworkInformation.PingCompletedEventArgs e)
        {
            if (e.Reply != null && e.Reply.Status == System.Net.NetworkInformation.IPStatus.Success)
            {
                // if previously thought we were offline and now looks like reconnected
                if (OnlineSuccess == 0)
                {
                    Reset();

                    foreach (DhtContact entry in IPs)
                    {
                        entry.NextTryIP    = new DateTime(0);
                        entry.NextTryProxy = new DateTime(0);
                    }
                }

                if (OnlineSuccess < OnlineConfirmed)
                {
                    OnlineSuccess++;
                }

                if (OnlineSuccess == OnlineConfirmed)
                {
                    Network.UpdateLog("general", "Online check success");
                }
            }

            // not success, try another random site, quickly (3 times) then retry will be 1 min
            else if (OnlineSuccess > 0)
            {
                OnlineSuccess--;

                LookupPingCheck();
            }
        }
Пример #3
0
 public void Ping_PingCompleted(object sender, System.Net.NetworkInformation.PingCompletedEventArgs e)
 {
     if (e.Reply.Status == System.Net.NetworkInformation.IPStatus.Success)
     {
         ipList.Add(e.Reply.Address.ToString());
     }
 }
Пример #4
0
            public void SendNextPingRequest(Logging.IBasicLogger logger)
            {
                if (ping == null)
                {
                    ping = new System.Net.NetworkInformation.Ping();
                    ping.PingCompleted += ping_PingCompleted;
                }

                lock (mutex)
                {
                    pingCompleteEventArgs  = null;
                    pingToReplyElapsedTime = TimeSpan.Zero;

                    currentUserToken = Token.SetToNow();

                    try
                    {
                        ping.SendAsync(IPAddress, responseTimeLimitInMSec, extraData, currentUserToken);
                    }
                    catch (System.Exception ex)
                    {
                        logger.Trace.Emit("{0} (SendAsync) generated unexpected exception: {1}", CurrentMethodName, ex.ToString(ExceptionFormat.TypeAndMessage));
                    }
                }
            }
Пример #5
0
 private void Ping_PingCompleted(object sender, System.Net.NetworkInformation.PingCompletedEventArgs e)
 {
     try
     {
         if (e.Reply != null && e.Reply.Status == System.Net.NetworkInformation.IPStatus.Success)
         {
             btnPing.Image = Properties.Resources.Green16x16;
             toolTip1.SetToolTip(btnPing, _localization.GetLocalizedString("PingOK"));
         }
         else
         {
             btnPing.Image = Properties.Resources.Red16x16;
             toolTip1.SetToolTip(btnPing, _localization.GetLocalizedString("CantPing"));
         }
     }
     catch (Exception) {  }
 }
Пример #6
0
 void ping_PingCompleted(object sender, System.Net.NetworkInformation.PingCompletedEventArgs e)
 {
     if (e != null)
     {
         lock (mutex)
         {
             if (currentUserToken != null && Object.ReferenceEquals(e.UserState, currentUserToken as object))
             {
                 pingCompleteEventArgs  = e;
                 pingToReplyElapsedTime = currentUserToken.sendTimeStamp.Age;
             }
             else
             {
                 unexpectedPingResponseCount++;
             }
         }
     }
 }
Пример #7
0
 private void AsyncPingCompleted(Object sender, System.Net.NetworkInformation.PingCompletedEventArgs e)
 {
     System.Net.NetworkInformation.PingReply reply = e.Reply;
     ((System.Threading.AutoResetEvent)e.UserState).Set();
     if (reply.Status == System.Net.NetworkInformation.IPStatus.Success)
     {
         Console.WriteLine("Address: {0}", reply.Address.ToString());
         Console.WriteLine("Roundtrip time: {0}", reply.RoundtripTime);
     }
     // Keep starting those async pings until all ips have been invoked.
     lock (_syncLock)
     {
         if (_omiToIP < _omiCurrentIp)
         {
             ++_omiCurrentIp;
             System.Net.IPAddress sniIPaddress = System.Net.IPAddress.Parse(IPn2IPv4(_omiCurrentIp));
             SendPingAsync(sniIPaddress);
         }
     }
 }
Пример #8
0
        void ph_PingComplete(object sender, System.Net.NetworkInformation.PingCompletedEventArgs p, params object[] parameters)
        {
            int idx = 0;

            int.TryParse(parameters[0].ToString(), out idx);
            VPNInfoEntity entity = (VPNInfoEntity)gd1.Rows[idx].DataBoundItem;

            if (p.Reply.Status == System.Net.NetworkInformation.IPStatus.Success)
            {
                entity.Ping      = p.Reply.RoundtripTime;
                entity.Available = VPNInfoEntity.AvailableStatus.Unknow;
            }
            else
            {
                entity.Ping      = -1L;
                entity.Available = VPNInfoEntity.AvailableStatus.Disable;
            }

            if (idx == gd1.Rows.Count - 1)//不允许添加新行,所以最后一行不是新行.
            {
                btnPing.BeginInvoke(BtnPingHandler, true);
            }
        }
Пример #9
0
        private void PingCompletedCallback(object sender, System.Net.NetworkInformation.PingCompletedEventArgs e)
        {
            if (e.Cancelled)                  // If the operation was canceled, display a message to the user.
            {
                ResultPing = "Ping canceled"; // UserToken is the AutoResetEvent object that the main thread  is waiting for.
                ((AutoResetEvent)e.UserState).Set();
            }

            if (e.Error != null)    // If an error occurred, display the exception to the user.
            {
                ResultPing = "Ping failed: " + e.Error.ToString();
                ((AutoResetEvent)e.UserState).Set(); // Let the main thread resume.
            }

            System.Net.NetworkInformation.PingReply reply = e.Reply;
            ((AutoResetEvent)e.UserState).Set();   // Let the main thread resume.

            statusPing = true;
            ResultPing = DisplayReply(reply);
            if (statusPort == true)
            {
                status = true;
            }
        }
Пример #10
0
 protected void OnPingCompleted(System.Net.NetworkInformation.PingCompletedEventArgs e)
 {
 }