public void close() {

        if (bdl != null) {
            bdl.close();
        }

        if (server != null) {
            server.close();
        }

        isConnected = false;
        boolean retry = true;

        while (retry) {

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


        System.out.println("Server stopped.");

    }