Reputation: 769
My server reading looks like this:
private fun init() {
val inStream = BufferedInputStream(socket.getInputStream())
val bytes = ByteArray(bufferSize)
outStream = DataOutputStream(socket.getOutputStream())
while (true) {
val count = inStream.read(bytes, 0, bufferSize)
if (count >= 0) {
server.onReceive(this, bytes, count)
}
}
}
First read waits until bytes received. But second doesn't wait. And loop is running forever and count is -1. I want to read bytes only when they received.
Upvotes: 0
Views: 1533
Reputation: 310875
And loop is running forever
You're looping at end of stream. If count
is -1 you should close the socket and exit the loop.
and count is -1
Exactly my point.
Upvotes: 2