title: send a big byte array through java socket
body: <p>I have a big byte array of length more than 1200000. I want to send it by DataOutputStream, and receive at client by DataInputStream.</p>
  
  <p>I'm using the code</p>
  
  <pre><code>    out.write(outData)
  
      in.readFully(inData)
  </code></pre>
  
  <p>out is DataOutputStream, in is DataInputStream, outData is the byte array I want to send.
  When I run the program, if the length of byte array is around 120000, the array can be sent, but when the length becomes 1200000, the server cant receive the array. Should I split the big array into some small ones?</p>
  
  <p>I tried such code below, but it still not working.</p>
  
  <pre><code>        out.writeInt(outData.length);
  
          int start = 0;
          int len = 0;
          int count = outData.length;
  
          while (count &gt; 0) {
              if (count &lt; 4096) 
                  len = count;
              else len = 4096;
  
              out.write(outData, start, len);
              start += len;
              count -= len;
          }
  </code></pre>
  
  <p>and            </p>
  
  <pre><code>        int length=in.readInt();
          byte[] inData=new byte[length];
          in.readFully(inData);
  </code></pre>
  
  <p>Can somebody help? Thanks.</p>