Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

java.rmi.ConnectException: Connection refused to host: localhost

843793Apr 10 2008 — edited Apr 10 2008
Hello,

I'm new to RMI and have a problem where I need your help.
I'd written a Java-Application which starts an RMI-Server.
When the RMI-Server is started, a local client connects to the RMI-Host, from localhost. This works fine.
If I connect later from a remote client, the remote client throws the following exception:
java.rmi.ConnectException: Connection refused to host: localhost; nested exception is:
java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:574)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:94)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:179)
] at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:132)

This happens even if the RMI-Server-Application is running.
The firewalls on both computers are disabled for the test.
If I run telnet <RMI-Host> <RMI-Port> I get a connection to the RMI-Host even from the remote computer.

Here is the code of the RMI-Host:
    private void registerAll() throws RemoteException
    {
        /*
         * Register the stubs in the registry
         */
        registerObj = new Register(this.registeredClients);
        registerStub = (IWatchdogCtrl) UnicastRemoteObject.exportObject(registerObj, 0);
        String registerRegistryname=((Register)registerObj).getFullRegistryname();
        registry.rebind(registerRegistryname, registerStub);
        
        messageObj = new Messaging(this.registeredClients);
        messageStub = (IMessaging) UnicastRemoteObject.exportObject(messageObj, 0);
        String messageRegistryname=((Messaging)messageObj).getFullRegistryname();
        registry.rebind(messageRegistryname, messageStub);
    }

    public void startWatchdog() throws IOException
    {
        if (System.getSecurityManager() == null) {
            System.setSecurityManager(new AllGrantSecurityManager());
        }
        String codebase=getCodebase();
        System.setProperty("java.rmi.server.codebase", codebase);
        System.setProperty("java.rmi.server.hostname", "localhost");
        try
        {
            /*
             * Create the registry on a specific port
             */
            registry = LocateRegistry.createRegistry(Watchdog.localPort);
            
            /*
             * Registers the stubs to the registry
             */
            registerAll();
            
            /*
             * Start the thread to exit, if no logins are present for a periode
             */
            startShutdownListener(idleTime);
}
The registry, RMI-Objects and RMI-Stubs are declared static.
The Shutdownlistener is an ownn thread to keep the server alive.
The AllGrantSecurityManager is a security manager, which don't throws any Exceptions.

Here is the code from the client, where the exception is thrown:
            System.setProperty("java.rmi.server.hostname", "Com-123");

            Registry registry=LocateRegistry.getRegistry("Com-123",7711);
            String applicationName = IWatchdogCtrl.APPLICATION_PREFIX + IWatchdogCtrl.REGISTRY_NAME;
            IWatchdogCtrl runOnApp = (IWatchdogCtrl)registry.lookup(applicationName);
            String v=runOnApp.getVersion();
            logger.debug(v);
The hostname and port is correct.
The applicationName is the same, the client is using on the localhost.
If I run the method, which throws an exception on localhost, all is running fine, too. Only if I want to access the RMI-Server on a remote pc, the exception is thrown.

Can anyone help me please?

Bye Kostarsus

Comments

User_C7DAK

Same issue - following

1 - 1
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on May 8 2008
Added on Apr 10 2008
1 comment
859 views