Note that there are some explanatory texts on larger screens.

plurals
  1. PObufferedreader is one line behind on real device
    primarykey
    data
    text
    <p>I got an socket client that i use to receive data from a server. In the emulator all works well, however on my android the messages are always lagging one behind on thus my GUI isn't updated with the new data.</p> <p>The code involved (the client runs in a Asynctask)</p> <pre><code>@Override protected Boolean doInBackground(Void... params) { //This runs on a different thread try { Log.i("AsyncTask", "doInBackground: Creating socket"); SocketAddress sockaddr = new InetSocketAddress("192.168.x.xxx", 9090); nsocket = new Socket(); nsocket.connect(sockaddr, 5000); //10 second connection timeout if (nsocket.isConnected()) { in = new BufferedReader(new InputStreamReader(nsocket.getInputStream())); wr = new BufferedWriter(new OutputStreamWriter(nsocket.getOutputStream())); Log.i("KMC.AsyncTask", "doInBackground: Socket created, streams assigned"); sockState = true; String inputLine = ""; while ((inputLine = in.readLine()) != null) { result = inputLine.replace("\\",""); Log.d("KMC", "Got some data: " + result); this.publishProgress(1); } } } catch (IOException e) { e.printStackTrace(); Log.i("KMC.AsyncTask", "doInBackground: IOException"); } catch (Exception e) { e.printStackTrace(); Log.i("KMC.AsyncTask", "doInBackground: Exception"); } finally { try { nis.close(); wr.close(); nsocket.close(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } Log.i("KMC.AsyncTask", "doInBackground: Finished"); } return true; } protected void onProgressUpdate(Integer... values) { try { JSONObject jObject = new JSONObject(result.substring(1, result.length()-1)); if(jObject.getString("type").equals("event")){ EventHandler.newEvent(jObject.getString("name"), jObject.getJSONArray("data")); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } </code></pre> <p>I've tried to find a solution on google, but i can't find anything on this.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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