私は2つのJavaクラスを持っていますが、クライアントはもう1つはサーバですが、クライアントはサーバのIPアドレスを与えなければなりませんが、クライアントはメソッド(DNSなど)を検索し、このメソッドを提供する特定のサーバーのIPアドレスを返す第3のマシン(ネーミングシステム)のIPを知っています。別のマシンでnamming system witj rmiを実行する方法
編集:
クラッセクライアント:
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