title: Getting byte arrays using TCP connections
body: <p>I was using <code>UDP</code> to send/receive data but I now want to switch to <code>TCP</code> to avoid packet loss.</p>
  
  <p>I've read several tutorials on <code>TCP</code> and noticed that instead of using DatagramPacket like <code>UDP</code>, <code>TCP</code> uses InputStream/OutputStream. </p>
  
  <p>How do we get the byte[] from DataInputStream, something that's similar to this:</p>
  
  <pre><code>byte[] receiveData = new byte[64000];
  DatagramPacket receivePacket = new DatagramPacket(receiveData,receiveData.length); 
  receiveData=receivePacket.getData();
  </code></pre>