Note that there are some explanatory texts on larger screens.

plurals
  1. POTransferring large amounts of data over bluetooth on Android Gingerbread
    primarykey
    data
    text
    <p>I'm trying to transfer about a megabyte of arbitrary data at a time from one android phone to another. Currently, I write the size, a command code and the data to a <code>DataOutputStream</code> around a <code>BufferedOutputStream</code>, around the <code>OutputStream</code> returned from <code>bluetoothSocketInstance.getOutputStream()</code>.</p> <p>The receiving phone reads the size and command code and then reads from the input stream until it has gotten all the data it is expecting. This works for short strings, but for larger files not all the data is transferred. Running the app in the debugger shows that the write returns without any exceptions and the read reads a fraction of the bytes expected and then blocks indefinitely. It also does not throw any exceptions. </p> <p>Is there a buffer somewhere that is filling up? Is there something else I need to do to ensure that all the data gets transferred?</p> <p>My code for the sender and receiver are below:</p> <p>Sender:</p> <pre><code> try { DataOutputStream d = new DataOutputStream(new BufferedOutputStream(mmOutStream,buffer.length+8)); //int b= buffer.length; d.writeInt(buffer.length); d.writeInt(command); d.write(buffer); d.flush(); } catch (IOException e) { Log.e(TAG, "Exception during write", e); } } </code></pre> <p>Receiver:</p> <pre><code> try { // Read from the InputStream int messageSize= inStream.readInt(); int messageCode = inStream.readInt(); bytes=0; buffer =new byte[messageSize]; while(bytes &lt; messageSize) { bytes += inStream.read(buffer,bytes,messageSize - bytes); } message = bytes; } catch (IOException e) { Log.e(TAG, "disconnected", e); connectionLost(); break; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload