title: Android to PC data exchange via Socket
body: <p>I have a Java desktop application acting like "server" and an Android application, that should be acting as a "client".<br>
  "Client" should send String and receive response String[] from "server". The only method, I've came across is using Sockets like this</p>
  
  <pre><code>Socket socket = null;
      try {
          Log.d(log_tag, "creating socket");
          socket = new Socket("192.168.1.123", 8090);
          Log.d(log_tag, "creating out");
          DataOutputStream out = new DataOutputStream(socket.getOutputStream());
          DataInputStream in = new DataInputStream(socket.getInputStream());
          Log.d(log_tag, "out created. sending data");
          out.writeUTF("sql");
          Log.d(log_tag, "data sent");
          Log.d(log_tag, "receiving data. loop");
          while(in.available() == 0);
          Log.d(log_tag, "received = " + in.readUTF());
          out.close();
          in.close();
          socket.close();
          Log.d(log_tag, "all closed");
      } catch (UnknownHostException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      }
      Log.d(log_tag, "finished");
  </code></pre>
  
  <p>"Server" is built the same way, except for order of operations(first read, then write response).</p>
  
  <p><strong>The problem</strong>: Android application freezes on line</p>
  
  <pre><code>while(in.available() == 0);
  </code></pre>
  
  <p>so, InputStream never gets ready and I can't receive server response, but "server" reports, that the data was sent.<br>
  Can you point me to my mistake(it's obvious one, I suppose, but I can't see it)?<br>
  P.S. Maybe that's the wrong way, but it's not an option to use any mid-layers here. I can't modify server code too.</p>