0

I am working on an android app that has continuous communication between the phone and a local server on the computer through cable and Android Open Accessory connection(AOA), the server(the computer) keeps sending packets of bytes to the android, then android parse them, all kinds of data gets received successfully.

In the implementation I am using BufferedInputStream like this:

val bufferedInputStream = BufferedInputStream(inputStream, 8192) // 8192 is the def buffer size

As I said everything works fine UNTIL android received a packet that is larger than 8192 which is the buffer size, in this case I need to loop until I read the whole packet is read(I know the size of the packets because I send that in the beginning of the packet)

When this kind of packet gets received, the call

bufferedInputStream.read(anyByteArrayOfTheWriteSize)

fails with message "Invalid argument", the annoying thing is that I can read the beginning of the packet which has the size and parse it successfully, so for example it tells android that the size of this packet is for ex 10192 bytes, this means that it needs to read 8192 then will do another iteration and read the remaining 200 bytes.

but it does not, it just fails once it reaches the call of the method read.

I was trying to use inputStream instead of bufferedInputStream but it did not work at all, bufferedInputStream kinda worked like magic, not sure why?! but this is not the topic of the question, just adding this info if incase it is needed.

asked Apr 7, 2022 at 0:21
3
  • And you do all without any code? Commented Apr 7, 2022 at 5:29
  • @blackapps I do it the very normal way of reading form inputStream. Commented Apr 7, 2022 at 11:53
  • @blackapps can u help me updating the question, because the code is very hard to add, like which part is needed, the things I thought might be needed is how to create the bufferedInputStream and the point that fails, the difference between this impl and any other implementation is that this one has an infinite loop and keeps looping forever because the communication is not expected to end I think that is why I am using BufferedInputStream instead of using the inputStream the I got from the usb connection directly. But the rest is just the same as any other tutorial. Commented Apr 7, 2022 at 12:39

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.