https://kotlinlang.org logo
#getting-started
Title
# getting-started
d

Daronee

02/19/2021, 12:48 AM
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

Jiddles

02/19/2021, 2:03 PM
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

Daronee

02/19/2021, 6:27 PM
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.
6 Views