3

I am trying to transfer file to remote bluetooth device as given below

    while (availableBytes > 0 ) {

                 bytesRead = inStream.read(tempData,0,tempData.length);

                 mmOutStream.write(tempData,0,bytesRead);  
                 mmOutStream.flush();
                 availableBytes = inStream.available();
    }/* End of availableBytes */

While write is in progress for large file ( 500 KB), I am getting IO exception as "IOException: Connection timed out" after 12 to 15 mins. When i am sending small file which is of < 100 KB, i am successful in transferring. I am not closing socket while file transfer is in progress. Is there any limitation in Android that Bluetooth socket can be active only for some fixed time limit?

Please throw your views on this

Vidz
  • 406
  • 2
  • 4
  • 16
  • Unrelated, but personally I wouldn't use `available()`. I'd keep reading until `bytesRead` is -1. – Jon Skeet Mar 16 '11 at 17:37
  • I think I am facing a similar issue as well http://stackoverflow.com/questions/9748219/bluetooth-file-transfer-android#comment12400097_9748219 – shiraz Mar 17 '12 at 12:50

1 Answers1

1

InputStream.available() does not do what you think it does:

Returns the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream.

The correct approach is to write until you hit bytesRead == -1, signalling EOF (End-of-File).

ThomasRS
  • 8,215
  • 5
  • 33
  • 48