Up Previous Next

Here's how the server needs to be started.

import java.rmi.*;
import java.rmi.server.*; 
import java.rmi.registry.*; 

public class Server extends UnicastRemoteObject implements ServerInterface {

  public Server() throws RemoteException { 
    System.out.println("Server being initialized..."); 
  } 

  public synchronized int register(ClientInterface client) throws RemoteException {
    size++;
    return size; 
  } 

  int size = -1; 

  public static void main(String[] args) {
    System.setSecurityManager(new RMISecurityManager()); 
    try {
      Server pam = new Server(); // start with java Server 18276 (port number)
      Registry cat = LocateRegistry.createRegistry(Integer.parseInt(args[0])); 
      cat.bind("Dirac", pam); // bind server under name of Dirac in registry
      System.out.println("Server is ready..."); 
    } catch (Exception e) {
      System.out.println("Server error: " + e + "... "); 
    } 
  } 
}
Network-related code (for startup, in main, appears in blue) is added separately.

The entire methodology reminds us of the separation induced by try/catch during exception handling.

This concludes the changes for the server. We can now compile the server-related files, if we wanted to.


Up Previous Next