c# - 'PingCompletedEventArgs.reply' 为空
问题描述
是什么导致回复为空?我正在通过 Unity3D 构建游戏。
该代码在我的 PC 上运行 - ping 成功完成,我可以访问reply.RoundtripTime
. 但是当在 iOS (iPhone) 上构建和运行时,回复仍然为空,即使_respose.Cancelled
是假的并且Error
是空的?手机已连接到互联网。
class MyPing{
public SNNI.Ping ping{ get; private set;} = null;
public Ip_Array ip{ get; private set;} = null;
public SNNI.PingCompletedEventArgs _response{ get; private set;} = null;
public bool _isDone{
get{ return _response != null; }
}
public MyPing( Ip_Array ip, int ms_timeout=1000 ){
this.ip = ip;
ping = new SNNI.Ping();
ping.PingCompleted += (object sender, SNNI.PingCompletedEventArgs r)=>{ _response = r; };
System.Net.IPAddress addr = new System.Net.IPAddress( ip.ip );
ping.SendAsync(addr, ms_timeout, null);
}
}
.
//somewhere else:
p = new MyPing( new Ip_Array("0.0.0.0") );//<--actual ip instead of this placeholder
.
//later, checking every frame of the game:
if(p._isDone == false){ continue; }
if(p._response.Cancelled || p._response.Error != null){ continue; }
else{
Debug.Log(p._response.reply.Status);//throws exception because .reply is somewhow 'null'
}
有趣的是,有一个使用 PingCompletedEventArgs 的示例,特别是该DisplayReply()
方法。他们在那里检查是否reply==null
但从不解释为什么它可能为空......
解决方案
推荐阅读
- angular - Angular 2:将数据从服务传递到组件
- bash - 如何在 bash 程序中运行命令?
- css - 设置 z-index 和变换?
- python - 元组在 group by 语句中被视为单个值,有什么解决方法吗?
- jquery - 计算一个元素是否具有某个类并且它的数据属性包含一个数字
- angular - Angular - 填充的服务对象返回 null
- google-compute-engine - 将 GPU 添加到现有 VM 实例 Google Compute Engine
- ios - “用户”类型的值没有“小写”成员
- ios - Flutter 可以实现 iOS 原生 iOS11 拖放功能吗?
- spring-boot - Spring Boot 2.1 与嵌入式 Tomcat 与 http/2 和 ssl,gzip 不工作