简体   繁体   中英

How does readInt() work in Android?

I am very new to network programming.

I have the bellow source running in one Thread. From other thread I am closing istream , ostream and socket , but still no IOException is printed from below code. I am running this code on an Android phone. On some Android phones, the behavior is proper and printing IOException , on other phones it's not printing.

I really want to know how readInt() really works. What might be problem in some handsets its not printing IOException?

while(true){
try {
int readInt=istream.readInt();
}
catch(IOException e){
Log.i("Sample","IOException");
}
}

You can read the source for readInt() to see what it really does. If you are trying to read beyond the end of the stream you should always get an EOFException.

If you are closing the thread from another thread. the VM should trigger a SocketClosedException, but it is possible some makes of Android phones don't honour this behaviour.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM