title: Android socket doesn't write to output
body: <p>I developed an application which communicates with server over TCP socket connection. When I tested it on emulator, it worked just fine. I could see all intended data flowing through. But when I run the application on my real device, it connects but not writes. To see what's happening, at server side I printed accepted clients and every received bytes. So it says "new client accepted" but never writes any received bytes which means no data received.</p>
  
  <p>My code on Android application, runs without any exception:</p>
  
  <pre><code>clientSocket = new Socket(host, port);
  PrintStream output = new PrintStream(clientSocket.getOutputStream());
  
  clientSocket.getOutputStream().write(new byte[]{67,68,75}); //just some random stuff
  clientSocket.getOutputStream().flush(); //neither this ...
  output.print("hello");                  //... nor this works
  </code></pre>
  
  <p>At the server side:</p>
  
  <pre><code>...
  
  Socket clientSocket = server.accept();
  DataStreamInput input = new DataInputStream(clientSocket.getInputStream());
  System.out.println("New client accepted");
  
  ...
  
  StringBuilder sb = new StringBuilder();
  char ch = (char)input.readByte();
  while (ch != '\0') {
       System.out.println("BYTE received: "+ch); //should print sth no matter what, but doesn't
       sb.append(ch);
       ch = (char)client.getInput().readByte();
  }
  
  String data = sb.toString().trim();
  dataReceived(data);
  </code></pre>
  
  <p>I don't understand why it works with the emulator but not with my device. (Samsung GT-I9500 btw) What could be the problem behind not sending or being unable to send the bytes? Any idea or any kind of help is appreciated. Thanks...</p>
  
  <p>Edit: Something interesting happened. When I print something to output later in a different thread, it sends all of them with previous data.</p>