Up Previous Next

public class Server implements ServerExports {
  int index = -1; 

  public int register(ClientExports client) { 
    clients[++index] = client;
    return index;
  }

  ClientExports clients[] = new ClientExports [100];
  public void broadcast(Update event) { }
  
}

public interface ServerExports { 
  public int register(ClientExports client);
  public void broadcast(Update event);
}

public class Simulation { 
  public static void main(String[] args) { 
    // on the server's host (server starts first)
    Server server = new Server();
    // on any of the clients' hosts 
    Client adrian = new Client("Adrian");
    Client bjorn = new Client("Bjorn");
    Client petchel = new Client("Tom");

    adrian.start();
    bjorn.start();
    petchel.start();
  }
}
public class Client extends Thread implements ClientExports { 
  String name;
  public Client(String name) { this.name = name; }
  public void update(Update event) { }
  public void run() {
    while (true) { 
      try { sleep((int)(Math.random() * 6000 + 1000)); }
      catch (Exception e) { }
      System.out.println(this.name + " here...");
    }
  }
}

public interface ClientExports {
  public void update(Update event);
}

public class Update {

}

Up Previous Next