try { while (true) { Object o = objectInputStream.readObject();
synchronized (clientSemaphore) { while (connection == null || connection.world == null) { try { clientSemaphore.wait(); } catch (InterruptedException e) {  } } }
    public synchronized World receiveWorld() throws IOException {	World w;        try {            while (true) {                Object o = objectInputStream.readObject();                if (o instanceof World) {		    w = (World) o;                    this.connection.world = (World)o;                    this.connection.setState(ConnectionState.READY);                    break;                } else {                    System.out.println("Received garbage whilst loading world:" +                        o);                }            }        } catch (ObjectStreamException e) {            System.out.println("Caught object stream exception whilst loading " +                "world");            throw new IOException(e.toString());        } catch (ClassNotFoundException e) {            System.out.println("Received unknown class instead of world " + e);            throw new IOException(e.toString());        }        worldNotYetLoaded = false;        /*         * wake up any thread waiting         */        notifyAll();        System.out.println("World received from server");	return w;    }