Code:
public String receive() {
InputStream is;
try {
is = socket.getInputStream();
} catch (IOException e) {
e.printStackTrace();
return null;
}
String result = new String();
int c;
while (true) {
try {
c = is.read(); //problem
if (c == -1) {
return result;
}
}
catch (IOException e) {
return result;
}
//System.out.print((char)c);
result += (char)c;
}
}
is.read() is supposed to give IOException when the stream ends. But its not throwing exception, instead the program keeps running and has to be stopped.
Anybody able to locate the mistake in the code?
I think mainly the problem is with reading end of the stream.
Thanks :)
Comment