}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
ss.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
class Client implements Runnable {
private Socket s;
private DataInputStream dis;
private DataOutputStream dos;
private boolean cont = false;
public Client(Socket s){
this.s = s;
try {
dis = new DataInputStream(s.getInputStream());//初始化
dos = new DataOutputStream(s.getOutputStream());
cont = true;
} catch (IOException e) {
e.printStackTrace();
}
}
public void send(String str){ //用于发送给客户端
try {
dos.writeUTF(str);
} catch (IOException e) {
clients.remove(this); //移除那个退出的对象
System.out.println("一个客户退出了");
//e.printStackTrace();
}
}
public void run() {
try{
while(cont){
String str = dis.readUTF(); //阻塞式方法
System.out.println(str);