日期:2014-05-20 浏览次数:21026 次
//其中hm的key为用户名,value为对应的通信线程,hashmap定义在ManagerClientSocket中
public class ManagerClientSocket {
//用hashmap来存放各个客户端与服务器的连接socket,并用客户名标识这些socket
public static HashMap<String,SerConClientThread> hm=new HashMap<String,SerConClientThread>();
//存存放线程
public static void addClientSocket(String uid,SerConClientThread sc){
hm.put(uid, sc);
}
//取得线程
public static SerConClientThread getClientSocket(String uid){
return (SerConClientThread)hm.get(uid);
}
}
//SerConClientThread是一个线程类,用于实现客户端与服务器的连接 SerConClientThread scct=new SerConClientThread(s); ManagerClientSocket.addClientSocket(u.getUsername(), scct);
SerConClientThread sc=ManagerClientSocket.getClientSocket(u.getUsername()); //取线程