Reputation: 1370
What causes the Reply to be null? I am building a game via Unity3D.
The code works on my PC - ping successfully completes, and I can access the reply.RoundtripTime
. But when building and running on iOS (iPhone), the reply remains null, even though the _respose.Cancelled
is false and Error
is null? The phone is connected to internet.
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'
}
Interestingly there is an example on using PingCompletedEventArgs, specifically the DisplayReply()
method. In there they check if reply==null
but never explain why it might be null...
Upvotes: 2
Views: 163