import java.rmi.Naming; import java.rmi.RemoteException; import java.rmi.server.UnicastRemoteObject; public class ServerImpl extends UnicastRemoteObject implements Server { private Client client1 = null; private Client client2 = null; public ServerImpl () throws RemoteException { super (4326); } public int connect (Client client) throws RemoteException { if (client1 == null) { client1 = client; return 1; } if (client2 == null) { client2 = client; return 2; } return 0; } public void option1 (int id) throws RemoteException { if (id == 1) client2.option1_from_server(); else if (id == 2) client1.option1_from_server(); } public String option2 (int id) throws RemoteException { if (id == 1) return client2.option2_from_server(); else if (id == 2) return client1.option2_from_server(); return "Unknown client"; } public static void main (String[] args) { try { ServerImpl server = new ServerImpl (); Naming.rebind ("//localhost:4236/Server", server); } catch (Exception e) { e.printStackTrace(); } } }