请各位高手帮忙看看客户端关了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, 而不是进入阻滞,或者是抛出异常.
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, 而不是进入阻滞,或者是抛出异常.
...全文
相关推荐
readline-devel-6.0-4.el6.x86_64.rpm
手动安装readline-devel-6.0-4.el6.x86_64。完美解决报错:readline-devel-6.0-4.el6.x86_64: failure: Packages/readline-devel-6.0-4.el6.x86_64.rpm from c6-media
详解python读取和输出到txt
主要介绍了python读取和输出到txt,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
自己编的一个直流电机转速控制程序,用液晶1602显示转速,键盘输入转速。并具有报错功能.zip
自己编的一个直流电机转速控制程序,用液晶1602显示转速,键盘输入转速。并具有报错功能.zip
centos下编译安装mysql报错解决方案
今天在centos6.2下面源码编译安装mysql的时,在编译mysql的时候报了一个蛋蛋的错误,本文提供详细解决方案
rlwrap-0.37.tar
rlwrap安装时候由于编译前验证时候会报错提示缺少包,安装下面3个既可 资源压缩包中包含上面3个rpm (64位) libtermcap-devel , readline , readline-devel


Java SE
