How do I ensure that RMI uses only a specific set of ports?

后端 未结 4 1159
旧时难觅i
旧时难觅i 2020-12-30 10:36

In our application, we are using RMI for client-server communication in very different ways:

  1. Pushing data from the server to the client to be displayed.
  2. <
4条回答
  •  囚心锁ツ
    2020-12-30 11:18

    I've been having various problems implementing an RMI Server/Client architecture, with Client Callbacks. My scenario is that both Server and Client are behind Firewall/NAT. In the end I got a fully working implementation. Here are the main things that I did:

    Server Side , Local IP: 192.168.1.10. Public (Internet) IP 80.80.80.10

    On the Firewall/Router/Local Server PC open port 6620. On the Firewall/Router/Local Server PC open port 1099. On the Router/NAT redirect incoming connections on port 6620 to 192.168.1.10:6620 On the Router/NAT redirect incoming connections on port 1099 to 192.168.1.10:1099

    In the actual program:

    System.getProperties().put("java.rmi.server.hostname", IP 80.80.80.10);
    MyService rmiserver = new MyService();
    MyService stub = (MyService) UnicastRemoteObject.exportObject(rmiserver, 6620);
    LocateRegistry.createRegistry(1099);
    Registry registry = LocateRegistry.getRegistry();
    registry.rebind("FAManagerService", stub);
    

    Client Side, Local IP: 10.0.1.123 Public (Internet) IP 70.70.70.20

    On the Firewall/Router/Local Server PC open port 1999. On the Router/NAT redirect incoming connections on port 1999 to 10.0.1.123:1999

    In the actual program:

    System.getProperties().put("java.rmi.server.hostname", 70.70.70.20);
    UnicastRemoteObject.exportObject(this, 1999);
    MyService server = (MyService) Naming.lookup("rmi://" + serverIP + "/MyService ");
    

    Hope this helps. Iraklis

提交回复
热议问题