Problem with RMI Creating an extra port

Greg Luck <[email protected]> Fri, 26 Sep 2008 05:46:31 -0600
Newsgroups gmane.comp.java.sun.rmi
Message-ID <LISTSERV%[email protected]>
Following is a simple example that sets a port for UnicastRemoteObject and for the RMI 
Registry.

I am having this problem with ehcache RMI replication (which I maintain) as reported my 
a user trying to get it to work through a firewall.

The problem is that when Naming.rebind() is called, a new random port gets listened on.

I do not understand why this is happening or how I can stop it from happening. This 
example follows the ways of controlling port usage as described in this list, from what I 
have read.

package net.sf.ehcache.distribution;

import java.rmi.registry.LocateRegistry;
import java.rmi.server.*;
import java.rmi.*;


public class RMIPortUsage extends UnicastRemoteObject {

    private static RMIPortUsage rmi;

    protected RMIPortUsage(int port) throws RemoteException {
        super(port);
    }

    public static void main(String[] args) throws Exception {
        int port = 10001;
        String service = "rmi://127.0.0.1" + ':' + port + '/' +
                "Pips";
        rmi = new RMIPortUsage(port);
        LocateRegistry.createRegistry(port);

        //Ports being listend to: 
        //Sep 26 21:29:52 Greg-Lucks-Laptop Firewall[57]: java is listening from 
::ffff:0.0.0.0:10001 uid = 501 proto=6
        Naming.rebind(service, rmi);


        //Ports being listened to:
        //Sep 26 21:29:52 Greg-Lucks-Laptop Firewall[57]: java is listening from 
::ffff:0.0.0.0:10001 uid = 501 proto=6
        //Sep 26 21:30:36 Greg-Lucks-Laptop Firewall[57]: java is listening from 
::ffff:127.0.0.1:57915 uid = 501 proto=6
        Thread.sleep(100000);

    }

}

===========================================================================
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff RMI-USERS".  For general help, send email to
[email protected] and include in the body of the message "help".

For a list of frequently asked RMI questions please refer to:
http://java.sun.com/j2se/1.3/docs/guide/rmi/faq.html

To view past RMI-USERS postings, please see:
http://archives.java.sun.com/archives/rmi-users.html