@Override
    public void run() {
        try {
            openConnection();
            while (running) {
                Socket socket;
                System.out.println("waiting for connection");
                socket = serverSocket.accept();
                ClientHandler h = new ClientHandler(new Connection(socket), messageHandler);
                Thread handlerThread = new Thread(h);
                handlerThread.start();
            }

        } catch (IOException e) {
            Logger.getLogger(ChatServer.class.getName()).log(Level.INFO, "disconnected");
        }
        System.out.println("server closed");
    }