tags:

views:

30

answers:

1

I have a problem with blocking buffer with the following code on my android application:

 else if (tcpdumpButton.isChecked())
           {
              try
              {
                 Process process1 = Runtime.getRuntime().exec("tcpdump");                     
                 BufferedReader osRes = new BufferedReader(new InputStreamReader(process1.getInputStream()));
                 StringBuffer output = new StringBuffer();
                 String line="";                     
                 while ((line = osRes.readLine()) != null)
                 {  
                    output.append(line);
                    output.append("\n");
                    tv.setText(output);
                    setContentView(tv);
                 }   
              }
              catch (Exception e)
              {
                 throw e;
              }

           }

Since the tcpdump process is running continuously and never terminated i am unable to print the buffer contents on the screen.Can anybody tell me what i should do or give an example on how to read the buffer and print it on the screen without waiting for the process to terminate??

A: 

Sounds to me like the tcpdump process should be in its own thread.

You should take a look at multithreading in java - this way the main thread can continue running as per normal, and the additional thread can deal with the tcpdump and update the main thread with the status.

http://www.devarticles.com/c/a/Java/Multithreading-in-Java/

xil3