title: How to speed up data transfer over socket?
body: <p>Currently I am using this code on both Server and Client Side. Client is an android device.</p>
  
  <pre><code>BufferedOutputStream os = new BufferedOutputStream(socket.getOutputStream(),10000000);
  BufferedInputStream sin = new BufferedInputStream(socket.getInputStream(),10000000);
  os.write("10000000\n".getBytes());
  os.flush();
  for (int i =0;i&lt;10000000;i++){
      os.write((sampleRead[i]+" ").getBytes());
      }
  os.flush();
  </code></pre>
  
  <p>The problem is that this code takes about 80 secs to transfer data from android client to server while it takes only 8 seconds to transfer the data back from server to client. The code is same on both sides and buffer is also same. I also tried with different buffer sizes but the problem is with this segment</p>
  
  <pre><code>for (int i =0;i&lt;10000000;i++){
       os.write((sampleRead[i]+" ").getBytes());
  }
  </code></pre>
  
  <p>The  buffering takes most of the time while the actual transfer takes only about 6-7 seconds on a 150mbps hotspot connection. What could be the problem and how to solve it?</p>