Код: Выделить всё
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>
В приведенном выше части кода мы не делаем ручную null check < /p>
для < /p>
Registry registry = LocateRegistry.getRegistry(host, port);
MyRemoteInterface stub = (MyRemoteInterface) registry.lookup("ServiceName");
Подробнее здесь: https://stackoverflow.com/questions/795 ... me-other-i