Ping - 取决于使用Ping.Send还是Ping.SendAsync的不同行为 [英] Ping - different behaviour depeding on whether using Ping.Send or Ping.SendAsync

查看:846
本文介绍了Ping - 取决于使用Ping.Send还是Ping.SendAsync的不同行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的程序,它使用Ping类发送ping。 TTL设置为2(作为示例)并且此跳跃为我超时(回复状态为'TimedOut')。
如果我执行类似的操作:
PingReply reply = ping.Send( " www.google.co.uk" ,2000,buffer, new PingOptions (2, true ));
reply.Address为null。

如果我执行以下操作:
ping.SendAsync( " www.google.co.uk" ,2000,buffer, new PingOptions < font size = 2>(2,
true ), null );
事件args的Reply.Address属性设置为主机的解析IP地址


显然我可以解决这个问题,Send和SendAsync之间存在不同的行为,这有点奇怪。任何人都可以确认这种行为,它是否正在"窃听"?或者我犯了一个简单的错误? :)

Al

Hi,
 I have a simple program which is sending a ping using the Ping class. The TTL is set to 2 (as an example) and this hop times out for me (reply status is 'TimedOut').
If I do something like:
PingReply reply = ping.Send("www.google.co.uk", 2000, buffer, new PingOptions(2, true));
reply.Address is null.

If I do something like:
ping.SendAsync("www.google.co.uk", 2000, buffer, new PingOptions(2, true), null);
The event args' Reply.Address property is set to the resolved IP address of the host I sent in.

Obviously I can work around this, it's just a bit odd that there is a different behaviour between Send and SendAsync. Can anyone else confirm this behaviour and is it working 'bugging'? Or have I made a simple mistake? :)

Al

推荐答案

您好,您可以使用Red Gate的.NET Reflector打开Ping类,看看如何实现Ping.Send()和Ping.SendAsync()方法。
Hi,

you can use Red Gate's .NET Reflector to open Ping class and see how Ping.Send() and Ping.SendAsync() methods are implemented.


这篇关于Ping - 取决于使用Ping.Send还是Ping.SendAsync的不同行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆