title: Asyncrhonous socket client
body: <p>I'm developing an asynchronous socket client based on threads.  When the program calls <code>readLine()</code>, it blocks indefinitely and never returns.</p>
  
  <pre><code>public class ADNClient {
  
    Socket socket = null;
    DataOutputStream dataOutputStream = null;
    DataInputStream dataInputStream = null;
  
    Thread listener = new Thread(new Runnable() {
      @Override
      public void run() {
        String line;
        try {
          // Stop here and doesn't progress
          while ((line = dataInputStream.readLine()) != null) {
            //DO something
          }
        } 
        catch (IOException e) {}
      });
  
      public ADNClient() {
      try {
        socket = new Socket("192.168.1.5", 5000);
        dataOutputStream = new DataOutputStream(socket.getOutputStream());
        dataInputStream = new DataInputStream(socket.getInputStream());
        listener.start();
        //sender.start();
      } catch (Exception e) {
        Log.e("ADN", e.getMessage());
      }
    }
  
    public void close() {
      listener.stop();
      try {
        socket.close();
      } catch (IOException e) {
        Log.e("ADN", e.getMessage());
      }
    }
  }
  </code></pre>