public void close() {

        if (networkClient != null && networkClient.isConnected()) {
            System.out.println("CLIENT: Closing connection.");
            networkClient.close();
        }

        running = false;
        boolean retry = true;

        while (retry) {

            try {
                join();
                retry = false;
                break;
            } catch (InterruptedException ex) {
            }
        }

        System.err.println("Client closed.");
    }