title: How to send a Gig of data through a Java socket?
body: <p>I'm trying to send a gigabyte sized byte array through a Java socket to my client in C#, but about 580k entries in my data is lost. I set every entry in my array to 10, but at a certain point they become 0s. </p>
  
  <p>My Java code:</p>
  
  <pre><code>OutputStream outputStream = objSocket.getOutputStream();
  
  byte[] dataBytesLength = new byte[4];
  int toSendLen = dataBytes.length;
  
  dataBytesLength[0] = (byte)(toSendLen &amp; 0xff);
  dataBytesLength[1] = (byte)((toSendLen &gt;&gt; 8) &amp; 0xff);
  dataBytesLength[2] = (byte)((toSendLen &gt;&gt; 16) &amp; 0xff);
  dataBytesLength[3] = (byte)((toSendLen &gt;&gt; 24) &amp; 0xff);
  
  outputStream.write(dataBytesLength);
  outputStream.write(dataBytes);
  </code></pre>
  
  <p>My C# code:</p>
  
  <pre><code>byte[] receivedLengthBytes = new byte[4];
  Socket.Receive(receivedLengthBytes);
  
  int receivedLength = BitConverter.ToInt32(receivedLengthBytes, 0);
  
  byte[] receivedBytes = new byte[receivedLength];
  Socket.Receive(receivedBytes);
  </code></pre>
  
  <p>If I loop over the array of received bytes, everything after 589824 is 0. I am not sure why this data loss is occurring, and splitting this into many 500k chunks is unfortunately not an option.</p>