/*
* This example is from the book "Java Enterprise in a Nutshell".
* Copyright (c) 1999 by O'Reilly & Associates.
* You may distribute this source code for non-commercial purposes only.
* You may study, modify, and use this example for any purpose, as long as
* this notice is retained. Note that this example is provided "as is",
* WITHOUT WARRANTY of any kind either expressed or implied.
*/
import java.rmi.Naming;
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
public class ThisOrThatServerTest {
public static void main(String argv[]) {
String host = argv[0];
String name = argv[1];
ThisOrThatServer server = null;
try {
Registry rmtRegistry = LocateRegistry.getRegistry(host);
server = (ThisOrThatServer)rmtRegistry.lookup(name);
System.out.println(server.doThis("thing"));
System.out.println(server.doThat("thing"));
}
catch (Exception e) {
e.printStackTrace();
System.out.println("Failed to connect to server.");
System.out.println("Let's try again, just for laughs");
try {
System.out.println(server.doThis("thing"));
System.out.println(server.doThat("thing"));
}
catch (Exception e2) {
System.out.println("Nope.");
}
}
}
}
|