class ServerImplementation extends NetworkPeer implements Server, Runnable, java.rmi.Remote { Client[] clients = new Client[100]; int index = -1; synchronized public void register(Client client) throws java.rmi.RemoteException { clients[++this.index] = client; client.setID(new Integer(this.index)); for (int i = 0; i < this.index; i++) { clients[i].register(new Integer(this.index), client); } for (int i = 0; i < this.index; i++) { client.register(new Integer(i), clients[i]); } } public void run() { while (true) { try { Thread.sleep((int)(Math.random() * 5000 + 5000)); this.broadcast(); } catch (Exception e) { } } } synchronized public void broadcast() throws java.rmi.RemoteException { for (int i = 0; i <= this.index; i++) clients[i].setAvailable(new Boolean(false)); String report = ""; String calculation = ""; int check = 0; for (int i = 0; i <= this.index; i++) { report += clients[i].report() + "\n"; calculation += "(" + clients[i].getBalance() + ").."; check += clients[i].getBalance(); } System.out.print("Server report indicates: \n" + report); System.out.println(calculation + " ---> " + check); for (int i = 0; i <= this.index; i++) clients[i].setAvailable(new Boolean(true)); } public void startAsLocalServer() { new Thread(this).start(); } public static void main(String[] args) { String portNumber = args[0], ownName = args[1]; ServerImplementation here = new ServerImplementation(); here.startAsNetworkServer(ownName, Integer.parseInt(portNumber)); } public void startAsClientOf(java.rmi.Remote peer) { // not needed, shows why a server is a client that has a public address (home, host) } }