Home / RMIV4V6

RMIV4V6


How to start RMIRegistry in the same port for both IPV4 & IPV6 host address

This article explains the following:
1. How to start RMIRegistry in the same port for both IPV4 & IPV6 host address
2. How to bind your objects for IPv4 address as well as IPv6 address in different names so that the same object is accessible in both the IPs

1. Download the source zip from here.

2. TestInvoker is the sample interface & TestInvokerImpl is the sample implementation.2. TestInvoker is the sample interface & TestInvokerImpl is the sample implementation.

3. SocketFactoryImpl is the socket factory implementation which works on the following principles:3. SocketFactoryImpl is the socket factory implementation which works on the following principles:
    1. Other than the RMI Registry port (1199 in this case), for v4/v6 implementation, the ServerSocket port is hardcoded as 6021/6020    1. Other than the RMI Registry port (1199 in this case), for v4/v6 implementation, the ServerSocket port is hardcoded as 6021/6020
    2. If the ipScheme is v6,
         In createServerSocket method:
            For the registry port, ServerSocket(Inet6Address,0,1199) is returned
            For any other ports (created randomly each time when we initialise the ServerSocketFactory), ServerSocket(Inet6Address,0,6020) is returned
    3. If the ipScheme is v4,
         In createServerSocket method:
                    For the registry port (1199 in this case) createServerSocket(Inet4Address,0,1199) is returned
                    For any other ports (created randomly each time when we initialise the ServerSocketFactory), ServerSocket(InetAddress,0,6021) is returned
    5. In createSocket method (this will NOT be called with random port - it will always be called only with 6020/6021 ports), based on v4/v6 ipScheme, Socket(Inet4Address,port) OR Socket(Inet6Address,port) is returned.

4. TestEngine is the server class which does the following:4. TestEngine is the server class which does the following:

1. Instantiates SocketFactoryImpl as server & client socket factory for both v4 & v6 schemes1. Instantiates SocketFactoryImpl as server & client socket factory for both v4 & v6 schemes
2. Calls LocateRegistry.createRegistry twice with respective socket factory instances so that it will be possible to start the RMI Registry twice in the same port - one in v4 address & one in v6 address.
3. Binds 2 instances of the same class (TestInvoker which extends UnicastRemoteObject) in 2 different names ("Test" & "Test6")

5. Effectively whatever work it takes to bind an object in the RMIRegistry is done twice to bind the same object to be accessed in RMI in both v4 & v6 addresses.
(The lookup names being different)

3. TestV4V6Client is the client side class which does the following:
Based on the name to lookup (Test/Test6), the ipScheme (v4/v6) and the address to lookup (IPv4/IPv6), Naming.lookup is called for the appropriate name.
 



     RSS of this page