[英]BufferedReader in not throwing an exception after connection to socket ends
当按下按钮时,我使用bufferedReader从客户端中的服务器读取输出,效果很好,但是当连接关闭时我无法使用方法errorHandling进行连接-我在尝试中包装了(bufferedreader对象).readLine / catch,但它不会引发异常,连接失败时out.checkError也不会返回true。 如果连接结束,该程序将完全冻结,并且不会达到最后的捕获。
if(source==button) {
String back = "";
if(out.checkError()){
errorHandling("I/O Closed");
return;
}
switch(currentOp){
case(0):
out.println("R "+input.getText());
break;
case(1):
out.println("P "+input.getText());
break;
case(2):
out.println("M "+input.getText());
break;
}
try{
if((back=in.readLine())==null) throw new SocketServerException();
}
catch(Exception e){
errorHandling("I/O Closed");
return;
}
您描述的情况是不可能的。 因此,这没有发生。 对等套接字必须仍然打开。 检查您的观察结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.