<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">
import java.rmi.server.UnicastRemoteObject;
import java.rmi.*;
import java.net.*;

// The implementation of the FlipServer remote object
public class FlipServerImpl extends UnicastRemoteObject
                            implements FlipServer {

    private boolean state;

    public FlipServerImpl() throws RemoteException {
	state = false;
    }

    public synchronized void flip() {
	state = !state;
    }

    public boolean getState() {
	return state;
    }

    // We register the FlipServer remote object in the main method:
    public static void main(String[] args) {
	try {
	    String host = args.length&gt;=1 ? args[0] : "localhost";
	    String uri = "rmi://" + host + "/" + FlipServer.NAME;

	    FlipServerImpl server = new FlipServerImpl();
	    Naming.rebind(uri,server);
	} catch (MalformedURLException e) {
	    e.printStackTrace();
	} catch (RemoteException e) {
	    e.printStackTrace();
	}
    }
}
</pre></body></html>