Server.java
public synchronized static void logout(String str) throws IOException{
Enumeration e = v1.elements();
while(e.hasMoreElements()){
Serverthread stm = (Serverthread)e.nextElement();
stm.send(str);
}
Enumeration ex=names.elements();
int indexOf = 0;
while(ex.hasMoreElements()){
String name=(String)ex.nextElement();
String org = str.substring(1);
if(name.equals(org)){
indexOf= names.indexOf(name);
names.removeElementAt(indexOf);
System.out.println("names"+names.size());
break;
}
}
// Serverthread st=(Serverthread)v1.get(indexOf);
Serverthread st=(Serverthread)v1.remove(indexOf);
st.close();
System.out.println(v1.size());
System.out.println("connection closed..");
}
通常,这样做的方法是关闭线程正在等待的InputStream。如果线程没有等待任何东西,那么停止它的唯一方法就是调用Thread.interrupt(),并希望线程检查它是否已被中断