Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Client Implementation Errors
    text
    copied!<p>Trying To let an android device get data from a server I have:</p> <pre><code>RetreiveFeedTask DoStuff=new RetreiveFeedTask(); try{ Work=(DoStuff.execute(Exec)).get(); } catch(Exception e) {System.out.print(e+"");} </code></pre> <p>Async Implementation:</p> <pre><code>class RetreiveFeedTask extends AsyncTask&lt;String , Void , String&gt; { //private Exception e; String GotBack="empty"; @Override protected String doInBackground(String... params) { try{ Socket socket = new Socket("192.168.1.66", 2727); OutputStream out = socket.getOutputStream(); PrintWriter output = new PrintWriter(out); BufferedReader input=new BufferedReader(new InputStreamReader(socket.getInputStream())); output.println(params[0]); output.flush(); output.close(); GotBack="OverWritten"; GotBack=input.readLine(); socket.close(); } catch(Exception e){System.out.print(e+"");} return GotBack; } </code></pre> <p>}</p> <p>My server is sending the ACK: "1\n"</p> <p>But what I get on the screen is "Overwritten" which is the value before I read data from the server. </p> <p>Any idea why?</p> <p><strong>Update</strong></p> <p>I was closing the output socket so it was throwing an exception. Now Im not getting errors but the value I get is empty. Any idea why?</p> <p>New Code:</p> <pre><code>class RetreiveFeedTask extends AsyncTask&lt;String , Void , String&gt; { //private Exception e; String GotBack="empty"; @Override protected String doInBackground(String... params) { try{ Socket socket = new Socket("192.168.1.66", 2727); OutputStream out = socket.getOutputStream(); PrintWriter output = new PrintWriter(out); BufferedReader input=new BufferedReader(new InputStreamReader(socket.getInputStream())); output.println(params[0]); output.flush(); String read=""; while((read=input.readLine())!=null) { GotBack+=read; } output.close(); socket.close(); } catch(Exception e){Log.e("MyApp","exception",e);} return GotBack; } </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload