I try to implement PING command on my application. The way I do it is by creating a process and then execute the command. When the PING command is finished, I parse the results from the console.
The method works fine. My problem is when I try to change the value of interval time for the PING command. PING can take as a parameter a value, that defines the interval between 2 packets send. When I execute the method from my application the results are way different from those that are executed using a terminal emulator.
The interval value stresses the device to send more packets in fewer time.I have set the interval value to 0.1 ms and have checked the results for both cases. The device works with the terminal emulator and has 1-2% loss. Using my application the results show 70-80% loss.
For interval of 1ms the results are the same. (device is not stressed out)
From the different tests that I have done I realized that the device loses many packets when the PING method is called within my application.
How is this possible? I thought that executing a command within a process would have the same results with executing it from a terminal emulator.Any ideas ?
I use the code from here Run shell commands from android program
I know that su is not required....
public void runAsRoot(String[] cmds) throws Exception {
Process p = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(p.getOutputStream());
InputStream is = p.getInputStream();
for (String tmpCmd : cmds) {
os.writeBytes(tmpCmd+"\n");
int readed = 0;
byte[] buff = new byte[4096];
boolean cmdRequiresAnOutput = true;
if (cmdRequiresAnOutput) {
while( is.available() <= 0) {
try { Thread.sleep(5000); } catch(Exception ex) {}
}
while( is.available() > 0) {
readed = is.read(buff);
if ( readed <= 0 ) break;
String seg = new String(buff,0,readed);
result=seg; //result is a string to show in textview
}
}
}
os.writeBytes("exit\n");
os.flush();