// standalone Fortune client // // Usage: FortuneClient [serverhost [port]] // // If serverhost is not specified, the local host is assumed // and the port number is read from the ./port file. // // If serverhost is specified then the port number defaults // to 21099 if not specified. // // R. Perry, June 1998 import java.io.*; import java.rmi.*; public class FortuneClient { public static int readPortFile() throws java.io.IOException { BufferedReader fin = new BufferedReader( new FileReader( "port")); int port = new Integer(fin.readLine()).intValue(); fin.close(); return port; } public static void main(String args[]) throws Exception { String serverhost = ""; int port = 21099; if( args.length == 0) port = readPortFile(); else { serverhost = args[0]; if (args.length > 1) port = Integer.parseInt(args[1]); } // Create and install the security manager // // skip to avoid creating a security policy file for JDK 1.2 - System.setSecurityManager(new RMISecurityManager()); String rmi = "rmi://" + serverhost + ":" + port + "/FortuneServer"; System.out.println( "FortuneClient: contacting " + rmi); Fortune f = null; try { f = (Fortune) Naming.lookup( rmi); System.out.println("FortuneClient: Message: " + f.getFortune()); } catch (Exception e) { System.out.println( "FortuneClient: " + e); System.exit(1); } // Can we do this? // // f.writePortFile(12345); // // No, we can't: // FortuneClient.java:57: Method writePortFile(int) not found in interface Fortune. } }