// remote Fortune client // // This client obtains the port number from a web server. // // Usage: HTTPClient [URL] // // If URL is not specified, a default URL is used. // // R. Perry, June 1998 import java.io.*; import java.rmi.*; import java.net.*; public class HTTPClient { public static void main(String args[]) throws Exception { String url = "http://www.ece.vill.edu/~perry/research/rmi-example2/port"; if( args.length > 0) url = args[0]; System.out.println( "HTTPClient: using URL: " + url); // Create and install the security manager // // skip to avoid creating a security policy file for JDK 1.2 - System.setSecurityManager(new RMISecurityManager()); URL u = new URL( url); String serverhost = u.getHost(); BufferedReader in = new BufferedReader( new InputStreamReader( u.openStream())); // an integer port number should be returned by the URL // int port = Integer.parseInt(in.readLine()); in.close(); String rmi = "rmi://" + serverhost + ":" + port + "/FortuneServer"; System.out.println( "HTTPClient: contacting " + rmi); try { Fortune f = (Fortune) Naming.lookup( rmi); System.out.println("HTTPClient: Message: " + f.getFortune()); } catch (Exception e) { System.out.println( "HTTPClient: " + e); System.exit(1); } } }