Code: Select all
public class RMIConnect {
public static void main(String[] args) {
try {
// String host = "host";
String host ="ip";
int port = 1999; // Default RMI registry port
Registry registry = LocateRegistry.getRegistry(host, port);
MyRemoteInterface stub = (MyRemoteInterface) registry.lookup("ServiceName");
String response = stub.someMethod();
System.out.println("Response from server: " + response);
} catch (Exception e) {
e.printStackTrace();
}
}
}
< /code>
Im obigen Code -Stück führen wir keine manuelle Nullüberprüfung < /p>
für < /p>
durchRegistry registry = LocateRegistry.getRegistry(host, port);
MyRemoteInterface stub = (MyRemoteInterface) registry.lookup("ServiceName");