Re: Problem with RMI Creating an extra port
Peter Jones <[email protected]> Fri, 26 Sep 2008 11:46:11 -0400
| Newsgroups | gmane.comp.java.sun.rmi |
|---|---|
| Message-ID | <20080926154611.GC23917@east> |
On Fri, Sep 26, 2008 at 05:46:31AM -0600, Greg Luck wrote:
> 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
This code indeed should only cause RMI to listen on one port (10001),
and that is in fact the case when I run it, with various JDK versions
on Solaris 10-- what JDK version and OS are you using?
The Naming.rebind invocation should not cause RMI to create any new
passive/listening sockets--- it would, however, cause the first
active/connecting socket to be created, to port 10001, for the RMI
call to the registry. Are you certain that the port 57915 (in the
above-described case) was not just the peer port on the client side of
that connection?
-- Peter
===========================================================================
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