0

Java RMI で単純なプログラムを使用してコールバックを実行しようとしています。localhost と LAN では問題なく動作しますが、NAT ルーターの背後では問題が発生します。

サーバー実装の場合、接続が拒否されextends UnicastRemoteObjectます。そうせずextends UnicastRemoteObjectにオブジェクトを手動でエクスポートすると ( UnicastRemoteObject.exportObject(services, 0);)、クライアントがリモート メソッドを呼び出したときにサーバーがアクションを実行し、サーバーがコールバック メソッドを呼び出すと、呼び出しがプライベート IP に送信されるため、接続タイムアウトが発生します。

次のように、サービスをレジストリにバインドします。

public class Server {
    private static final String SRVHOST = "<<external ip>>";
    private static Registry registry;

    public static void main(String[] args) {
        System.setProperty("java.rmi.server.hostname", SRVHOST);
        System.setProperty("java.rmi.server.useCodebaseOnly","false"); 
        System.setProperty("java.security.policy","src/srv.policy");

        if(System.getSecurityManager()==null)
            System.setSecurityManager(new RMISecurityManager());

        registry = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
        ServerInterface services = new ServerImpl();
        registry.rebind("ServerAPI", services);
    }
}

クライアントはサービスを取得します。

public class Client {
    private static final String SRVHOST = "localhost";
    private static Registry registry;
    private static ClientInterface callback;

    public static void main(String[] args) {
        System.setProperty("java.security.policy", "src/cli.policy");

        if(System.getSecurityManager()==null)
            System.setSecurityManager(new RMISecurityManager());


        registry = LocateRegistry.getRegistry(SRVHOST, Registry.REGISTRY_PORT);
        ServerInterface services = (ServerInterface) registry.lookup("ServerAPI");
        callback = new ClientImpl();
        int nCallback = services.setClientInterface(callback);
        ...
        <<do_things>>
    }
}

このメソッドsetClientInterface(...)はクライアント オブジェクトを取得し、ArrayList.

何が問題なのかわからない。誰かが私を助けることができますか?

すべてのコードは次の場所で公開されています。

ポリシー ファイル:

srv.policy - http://pastebin.com/LTsKSG3r

cli.policy - http://pastebin.com/zqxaRyT3

パッケージ: com.rmicallback.client

Client.java - http://pastebin.com/Xus04JZK

ClientImpl.java - http://pastebin.com/SdQXMDzs

ClientInterface.java - http://pastebin.com/S9PxT5vC

パッケージ: com.rmicallback.server

Server.java - http://pastebin.com/cxQcWy1Q

ServerImpl.java - http://pastebin.com/nqdGPbPr

ServerInterface.java - http://pastebin.com/nPxDJgs1

4

0 に答える 0