Up Previous Next

Here's what we have at this stage:

class Setup {
  public static void main(String[] args) {

    Server server = new Server(); 

    Client a = new Client(); 
    a.registerWith(server); 

    Client b = new Client(); 
    b.registerWith(server); 

    Client c = new Client(); 
    c.registerWith(server); 

  } 
}

public interface ServerInterface {
  public int register(ClientInterface client);
}

public class Server implements ServerInterface {
  public int register(ClientInterface client) {
    size++;
    return size; 
  } 
  int size = -1; 
}
public interface ClientInterface {
  
}

import java.awt.*; 
import javax.swing.*; 

public class Client extends JFrame implements ClientInterface { 

  public Client() {
    this.setTitle("iceblox: client frame"); 
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    this.setSize(300, 200); 
    this.setVisible(true); 
  }   

  ServerInterface server; 

  public void register(ServerInterface server) {
    this.server = server; 
    this.id = server.register(this);     
    System.out.println("I have registered, I have id: " + this.id); 
  } 

  int id = -1; 
}
This is, as a matter of fact, is all we need for now.

We will distribute the clients and the server on separate machines now.

If we can do it now we can do it later too.

Let's see what it involves.


Up Previous Next