【问题标题】:C# Ping - how many attempts?C# Ping - 多少次尝试?
【发布时间】:2015-10-21 22:45:38
【问题描述】:

我正在使用 System.Net.NetworkInformation 库来 ping IP 地址以测试连接性。我想知道在失败之前它会尝试多少次?例如,如果你在 CMD 中 ping,它会尝试 4 次。另外,如果它尝试了多次尝试,当一些失败和一些通过时,它如何声明成功或失败?

我似乎在文档中找不到任何内容。

提前致谢!

【问题讨论】:

  • 通过阅读这行文档,听起来它只尝试了一次。 This method sends to the host that is specified by address a 32 Byte data buffer with the ICMP echo message. 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.
  • 显然没有很认真地看文档。
  • 这一切都在您必须阅读的文档中。

标签: c# ip-address ping


【解决方案1】:

Ping.Send() 方法将发送单个缓冲区并等待超时。

根据该参考:

此方法发送带有 ICMP 回显消息的 32 字节数据缓冲区该方法等待 ICMP 回显回复消息 5 秒如果在那段时间内没有收到回复,则该方法返回并将 Status 属性设置为 TimedOut。

所以要直接回答您的问题,需要 1 次尝试

【讨论】:

    【解决方案2】:

    Ping.Send() 的每次调用都会发送一条 ICMP 消息并阻塞,直到收到响应、发生错误或超时。

    【讨论】:

      猜你喜欢
      • 2020-06-29
      • 1970-01-01
      • 1970-01-01
      • 2021-02-04
      • 2019-03-30
      • 2021-04-04
      • 1970-01-01
      • 2012-01-18
      • 1970-01-01
      相关资源
      最近更新 更多