Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ping timeout command -W not working for Android

Tags:

android

ping

In my Android application, I have used the ping command with appropriate option mentioned in below link: http://linux.about.com/od/commands/l/blcmdl8_ping.htm

All other options are working except -W which is timeout.

I am using this command to ping with 5sec time out: ping 131.107.8.1 -W 5 I believe this should give "Request timed out" after 5sec. I also tested it with "Test Ping" application but it failed there as well.

Where as in my windows machine, I am using this command for same IP: ping 131.107.8.1 -w 7000 And it is properly giving "Request timed out" after 7000msec.

Any pointer where am I missing the concept?

like image 629
Shravan Avatar asked Jul 30 '13 15:07

Shravan


1 Answers

I'm not entirely sure on Android's implementation of Ping, but on Linux the flags ping -w and ping -W have very different operations.

In this case, you're using ping -W, which waits for a timeout to happen across the network. According to the man page:

-W timeout Time to wait for a response, in seconds. The option affects only timeout in absense of any responses, otherwise ping waits for two RTTs.

I believe what you're attempting to do is set a deadline for the Ping command, e.g. ping -w as described by the man page again:

-w deadline Specify a timeout, in seconds, before ping exits regardless of how many packets have been sent or received. In this case ping does not stop after count packet are sent, it waits either for deadline expire or until count probes are answered or for some error notification from network.

like image 55
hakusaro Avatar answered Nov 08 '22 04:11

hakusaro