日期:2014-05-20 浏览次数:21028 次
//比如Vector存储的是Connections类别 static Vector<Connection> connVector=new Vector<Connection>(10)//存储建立连接的Connection ... ...//关于Connection类的实现就省略了,为了简单变量的定义也省略,只说主要问题 socket = server.accept();//make a connection with client System.out.println(socket.getInetAddress().toString()+"joined the server\n"); Connection connect=new Connection(socket); connVector.add(connect);//把建立的链接存入connVector
    while(connVector.size()>0){
        Connection connect=(Connection)connVector.firstElement();//取出Vector中第一个服务器客户机的Tcp链接
        try{
            connect.socket.close();//socket 是Connection中定义的方法
        }catch(IOException ex){
            ex.printStackTrace();
        }
        connVector.removeElement(connect);//ok我的问题主要在这一步
    }
 public synchronized int indexOf(Object o, int index) {
    if (o == null) {
        for (int i = index ; i < elementCount ; i++)
        if (elementData[i]==null)
            return i;
    } else {
        for (int i = index ; i < elementCount ; i++)
        if (o.equals(elementData[i]))
            return i;
    }
    return -1;
    }