I am using System.Net.NetworkInformation.Ping class to ping a certain Ip. I am working on an Android Form application using Xamarin and visual Studio 2015. Here is the code that I am using.
int timeout = 100;
Ping ping= new Ping();
PingReply reply = ping.Send("209.197.25.1", timeout);
if (reply != null && reply.Status == IPStatus.Success)
return reply.RoundtripTime;
if (reply != null && reply.Status == IPStatus.TimedOut)
return -1;
One thing is that if my WiFi is connected then I never get timed-out no matter how small i give the timeout value (as low as 1), and the reply.RoundtripTime is greater than the timeout(almost 300 for this server from my location). But if my WiFi is off then I get timed-out according to the time I specified.
I also tried to run the same code on C# console application and it works perfectly fine there. I have also tried different servers and the result is same. Can someone tell me what I am doing wrong? Some people figured that I am using this code to check if the destination is available, but I am not, I am interested in the round trip time from one pc to another.