sanchop22
sanchop22

Reputation: 2809

Default ping timeout

What is the default time of ping? I use the code below to send ping to tcp devices. When does IPStatus fall to timeout?

private static void ApplyPing(Topology.Runtime rt)
{
    try
    {
        if (rt.TcpClient != null)
        {
            string ip = rt.Ip;
            if (new Ping().Send(ip).Status != IPStatus.Success)
            {
                Service.WriteEventLog(string.Format("{0} ping error.", ip), EventLogEntryType.Warning);
                rt.Disconnect();
            }
        }
    }
    catch (ArgumentNullException ex)
    { 

    }
    catch (Exception ex)
    {
        Service.WriteEventLog(ex, EventLogEntryType.Error);
    }
}

Thank you.

Upvotes: 13

Views: 21161

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062770

From MSDN here and here

The method waits five seconds for an ICMP echo reply message. If it does not receive a reply in that time, the method returns and the Status property is set to TimedOut.

And if we check in reflector, indeed we see:

public PingReply Send(string hostNameOrAddress)
{
    return this.Send(hostNameOrAddress, 5000, this.DefaultSendBuffer, null);
}

Upvotes: 25

Related Questions