You should make it like you said, receivedAmount==ExpectedAmount;
You should also make a
long = System.getCurrentTimeMillis()
of when last bytes where received.
If last bytes were received from more than N amount of time, kill the loop, and say to the user that connection has been lost, or some kind of error happened. Basically make a kill switch that would kill your loop if no bytes were received for N amount of time. (N should be time that would allow for some lag, but not big enough that user would get annoyed by looking at stuck UI)