1

Problem:

in my code, I set a timeout of a ping to 100ms

new Ping().Send(item._deviceIP, 100, new byte[1])

which pings correctly and replies correctly, but the IPStatus.TimeExceeded is "faulty" and reports a success after the RTT is > 100ms

What should happen:

when recieving a pingreply, if the IPStatus is a:

  • TimeExceeded (>100ms), _devicePing should have a color set to Red

  • Success(<=100ms), _devicePing should have a color set to green

  • any other, appropriate color is set.

What happens:

Any ping reply which is a reply report success even with a RTT >100ms

class device

{
    public IPAddress _deviceIP;
    public string _deviceMAC;
    public string _deviceName;
    public PingReply _devicePing ;
    public Color _deviceStatus = Color.White;
    public int _timeout_Count = 0;

    public Color deviceStatus
        {
            get { return _deviceStatus; }
            set { _deviceStatus = value; }
        }

Main Program Code

List<device> _alive = new List<device>();
foreach (device item in _clients)
{
    PingReply _client_reply = new Ping().Send(item._deviceIP, 100, new byte[1]);
    item._devicePing = _client_reply; (item object accepts a PingReply)
    IPStatus _client_status = _client_reply.Status;
    switch (_client_status)
    {
        case IPStatus.TimeExceeded:
        {
            item.deviceStatus = Color.Red;
        }        
        break;

    //rest of code
CybeX
  • 2,060
  • 3
  • 48
  • 115

1 Answers1

0

You will need to check the status of the PingReply in all cases. When specifying very small numbers for timeout, the Ping reply can be received even if timeout milliseconds have elapsed.

And now you ask the difficult question - what is a very small number 500ms, 250ms, 100ms 10ms, ??? Glad you asked .. see this article for no answwer to that question. https://msdn.microsoft.com/en-us/library/ms144954%28v=vs.110%29.aspx

Ken
  • 2,518
  • 2
  • 27
  • 35
  • I know about this, but how does this solve my problem? Or rather, should I do my own TimeElapsed checking, since this is what it boils down to? – CybeX Dec 12 '15 at 13:09
  • @KGCybeX - you will need to perform your own time elapsed checking. You can check in the pingreply if is > timeout = fail. I do not know any way to make the .NET library behave different than how it behaves - so you need to either work around it or roll your own. The work around is easier. – Ken Dec 13 '15 at 23:58