Could anyone help me out with reading from the Inp...
# getting-started
d
Could anyone help me out with reading from the InputStream? Whenever I receive the data and put it into a buffer, the elements in it seems to be inconsistent. For example I am expecting a buffer of [0,0,0,0,0,0,4,3,0]. sometimes I get the right values sometimes I get [0,0,0,0,0,0,3,0,0], or [0,0,0,0,0,0,0,3,4] or some different variation. I am not entirely sure if there is not enough time to update the buffer properly before it is being evaluated or if there is some other problem. This is being done within a
run()
function of a thread Its like the app is receiving the data from the inputstream consistently. It always varies Seems to be a problem when the number of bytes > ~6 for some reason?
j
Not done loads with InputStream so far but looking at the Java docs here, https://docs.oracle.com/javase/9/docs/api/java/io/InputStream.html seems the
transferTo
explictly says it maintains the order. Maybe give that a try and see if there’s any difference ?
d
i actually tried changing my original
socket.inputStream.read(buffer)
was just not having it in terms of recieving Byte data. I changed my buffer from a ByteArray to a charArray and received the data using `val ch = socket.inputStream.read().toChar`and got way better results.