public void close(){
        
        write("Shutting down the server");
        try {
            // disconnect every client from the server
            // close all the sockets of the threads 
            for (int i=0; i<clientList.size();i++){
                if (clientList.get(i).isRunning()){
                    log.writeLn(clientList.get(i).toString());
                    clientList.get(i).send("disconnect");
                    clientList.get(i).stop();
                }
            }
            socket.close(); // close the server socket
            
            socket = null;
            clientSocket = null;
            run = false;
            clientList = null;
        } catch (IOException ex) {
            writeErr("Could not stop server. Closing forcefully");
            System.exit(-1);
        } catch (NullPointerException ex){
            writeErr("Found the server sockets were already closed. Closing forcefully.");
            System.exit(-1);
        }
        
        write("Stopped Server");
    }