请各位高手帮忙看看客户端关了readLine()为什么不报错.
import java.io.IOException;
import java.io.*;
import java.net.*;
public class ChatServer {
public static void main(String[] args) {
ServerSocket ss = null;
BufferedReader br = null;
Socket s = null;
boolean started = false;
try {
ss = new ServerSocket(8888);
} catch (BindException e) {
System.out.println("The port is already in use, please replace the port!");
System.out.println("The program has been in operation, please close and re run the program!");
System.exit(0);
} catch (IOException e) {
e.printStackTrace();
}
try {
started = true;
while(started) {
boolean bConnected = false;
s = ss.accept();
bConnected = true;
System.out.println("a Client connected!");
br = new BufferedReader(new InputStreamReader(s.getInputStream()));
while(bConnected) {
String str = br.readLine();
System.out.println(str);
}
System.out.println("a Client connected!");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if(br != null) br.close();
if(s != null) s.close();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Client Closed!");
}
}
}
请帮忙看下代码中标红的地方.readLine()与readUTF()这个方法都是阻滞式的,为什么把客户端关了之后,就一直输出null, 而不是进入阻滞,或者是抛出异常.