title: Android bluetooth chunk size
body: <p>I'm experiencing a strange behavior of bluetooth socket (in my opinion), and I would like know if anybody can clarify it to me.</p>
  
  <hr>
  
  <h2>The situation:</h2>
  
  <p>I have two Android applications connected together by a Bluetooth socket:</p>
  
  <ul>
  <li>The first makes a simple <code>write(byte[] message)</code> on the output stream.</li>
  <li>The second makes a simple <code>read(byte[] buffer)</code> on the input stream.</li>
  </ul>
  
  <p>On the reader side I use a buffer of <strong>1024</strong> bytes. The sender send a message a little bit larger than the receiver buffer size: <strong>1024</strong> + <strong>108</strong> bytes (always the same message).</p>
  
  <h2>Ok now the behavior:</h2>
  
  <p>On the reader app I receive the most often a first chunk of <strong>1024</strong> bytes which fills up the buffer (as expected) and then a second one of <strong>108</strong> bytes.</p>
  
  <p>But really often (maybe 40% of the time) I receive a first chunk of <strong>1008</strong> bytes and then a second one of <strong>124</strong> bytes. </p>
  
  <hr>
  
  <p>I really would like to understand this because I'm affraid to miss an important bluetooth concept. At first I was thinking to compare the count of byte read with the buffer size to know if the entire message had been received but this experimentation shows that it's maybe not a good idea.</p>
  
  <p>Is anybody can explain to me this behavior? </p>
  
  <p>Thanks in advance.</p>