1

I retrieve some data from json in asyntask and go to another page without finishing retrieve data in json. Socket exception (warning) is occured. Here is the log cat.

04-24 07:41:45.565: W/SingleClientConnManager(2504): Invalid use of SingleClientConnManager: connection still allocated.
04-24 07:41:45.565: W/SingleClientConnManager(2504): Make sure to release the connection before allocating another one.
04-24 07:41:45.795: W/System.err(2504): java.net.SocketException: Socket closed
04-24 07:41:45.845: W/System.err(2504):     at libcore.io.Posix.recvfromBytes(Native Method)
04-24 07:41:45.845: W/System.err(2504):     at libcore.io.Posix.recvfrom(Posix.java:141)
04-24 07:41:45.845: W/System.err(2504):     at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:164)
04-24 07:41:45.855: W/System.err(2504):     at libcore.io.IoBridge.recvfrom(IoBridge.java:506)
04-24 07:41:45.855: W/System.err(2504):     at java.net.PlainSocketImpl.read(PlainSocketImpl.java:488)
04-24 07:41:45.895: W/System.err(2504):     at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:46)
04-24 07:41:46.005: W/System.err(2504):     at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:240)
04-24 07:41:46.005: W/System.err(2504):     at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:103)
04-24 07:41:46.095: W/System.err(2504):     at org.apache.http.impl.io.AbstractSessionInputBuffer.read(AbstractSessionInputBuffer.java:134)
04-24 07:41:46.135: W/System.err(2504):     at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:161)
04-24 07:41:46.135: W/System.err(2504):     at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:159)
04-24 07:41:46.145: W/System.err(2504):     at java.io.InputStreamReader.read(InputStreamReader.java:233)
04-24 07:41:46.145: W/System.err(2504):     at java.io.BufferedReader.fillBuf(BufferedReader.java:145)
04-24 07:41:46.145: W/System.err(2504):     at java.io.BufferedReader.readLine(BufferedReader.java:397)
04-24 07:41:46.145: W/System.err(2504):     at com.speedlink.common.Global.executeHttpPost(Global.java:76)
04-24 07:41:46.145: W/System.err(2504):     at com.speedlink.common.WheelDataRetriever.doInBackground(WheelDataRetriever.java:46)
04-24 07:41:46.145: W/System.err(2504):     at com.speedlink.common.WheelDataRetriever.doInBackground(WheelDataRetriever.java:1)
04-24 07:41:46.225: W/System.err(2504):     at android.os.AsyncTask$2.call(AsyncTask.java:288)
04-24 07:41:46.255: W/System.err(2504):     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
04-24 07:41:46.265: W/System.err(2504):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
04-24 07:41:46.265: W/System.err(2504):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
04-24 07:41:46.305: W/System.err(2504):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
04-24 07:41:46.305: W/System.err(2504):     at java.lang.Thread.run(Thread.java:841)

How can I solve this warning?

Edit:

       protected String doInBackground(String... arg0) {
     if (isCancelled()){
         cancel(true);
         return "";
      }else{
    try {
        postParameters.add(new BasicNameValuePair("keyCode",Encode.getKeyCode()));
        postParameters.add(new BasicNameValuePair("version",Encode.getVersion()));
        string response = vv.executeHttpPost(vv.common_URL()+"abc.php",postParameters);


    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
      }
}
Halo
  • 729
  • 1
  • 8
  • 18

1 Answers1

0

You need to consume the response body before you can reuse the connection for another request. You should not only read the response status, but read the response InputStream fully to the last byte whereby you just ignore the read bytes.

Use this link for more details

Community
  • 1
  • 1
SacreDeveloper
  • 1,253
  • 1
  • 9
  • 16