나는 두 개의 자바 클래스를 가지고 있는데 하나는 클라이언트이고 다른 하나는 서버이다. 클라이언트는 서버 IP 주소를 주어야한다.하지만 나는 다이나믹하게 만들고 싶다. 클라이언트는 DNS와 같은 메소드를 검색하고이 메소드를 제공하는 특정 서버의 IP 주소를 리턴하는 세 번째 시스템 (이름 지정 시스템)의 IP를 알고 있습니다.다른 컴퓨터에서 namming system witj rmi하는 방법
편집 :
CLASSE 클라이언트 :
public class Client {
private Client() {}
public static void main(String[] args) {
String host = (args.length < 1) ? null : args[0];
try {
//Registry registry = LocateRegistry.getRegistry(host);
Registry registry = LocateRegistry.getRegistry("192.168.1.9",1091);
Calculator stub = (Calculator) registry.lookup("Hello");
String response = stub.add(4,2);
System.out.println("response: " + response);
} catch (Exception e) {
System.err.println("Client exception: " + e.toString());
e.printStackTrace();
}
}
}
서버 :
public class Server implements Calculator{
public Server() {}
public String add(int a,int b) {
return "Hello, a+b= "+(a+b);
}
public String sub(int a,int b) {
return "Hello, a-b= "+(a-b);
}
public static void main(String args[]) {
try {
Server obj = new Server();
Calculator stub = (Calculator) UnicastRemoteObject.exportObject(obj, 0);
// Bind the remote object's stub in the registry
Registry registry = LocateRegistry.createRegistry(1091);
registry.bind("Hello", stub);
System.err.println("Server ready");
} catch (Exception e) {
System.err.println("Server exception: " + e.toString());
e.printStackTrace();
}
}
}
코드 또는 지금까지 시도한 것을 제공해주십시오. – Yannis
나는이 질문에 대해 '너무 광범위하다'라는 것을 모른다. – EJP