title: Can't read socket InputStream on Jelly Bean
body: <p>I have a TCP socket connection which works well on Android 2.3 but now facing some problems on Android 4.1.
  The problem is that InputStream.read() method always returns -1 (without blocking), like the connection is closed.</p>
  
  <p>Creating socket:</p>
  
  <pre><code>SocketFactory socketFactory = SocketFactory.getDefault();
  Socket socket = socketFactory.createSocket("c.whatsapp.net", 5222);
  socket.setSoTimeout(3*60*1000);
  socket.setTcpNoDelay(true);
  </code></pre>
  
  <p>Retrieving input and output streams and writing some initial data:</p>
  
  <pre><code>InputStream inputStream = new BufferedInputStream(socket.getInputStream());
  OutputStream outputStream = new BufferedOutputStream(socket.getOutputStream());
  
  outputStream.write(87);
  outputStream.write(65);
  outputStream.write(1);
  outputStream.write(2);
  outputStream.flush();
  </code></pre>
  
  <p>Then, this condition always passes without blocking:</p>
  
  <pre><code>int c = inputStream.read();
  if (c &lt; 0) {
      Log.d(TAG, "End of stream");
  }
  </code></pre>
  
  <p><strong>This code is running in a background thread</strong>. And it was working on Gingerbread.</p>
  
  <p>Tried to use InputStreamReader and OutputStreamWriter instead of direct streams - no effect.</p>