@Override
    public void run() {
        name = Thread.currentThread().getName();
        write("Opening up socket.");
        try {
            socket = new ServerSocket(2226);
        } catch (IOException e){
            writeErr("Could not open port 2226. \nEither an instance of Chat Server is already \nrunning or another program is using the \nsocket.");
            System.exit(-1);
        }
        run = true;
        
        while (run){
            try {
                // wait for clients if the maxclients isnt maxed out
                clientSocket = socket.accept();
                if (getClients() < MAXCLIENTS){
                    clientList.add(new Client(clientSocket, clientList.size(), this)); // need a better way to get client index                    
                } else {
                    log.writeLn("Too many clients. MAXCLIENTS IS: " + MAXCLIENTS);
                    try (PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true)) {
                        out.write("d");
                    }
                }
            } catch (IOException ex) {
                writeErr("Could not accept socket from client.\nShutting down the server thread.");
                close();
            }
        }
    }