RMI & connection refused



I'm suffering from the the common "java.rmi.ConnectException: Connection
refused to host" problem.

I've searched the web and found this problem described many times.
However, the solutions, range from changing /etc/hosts to doing really
weird stuff -- but nothing applicable. ;)

All the online RMI tutorials and examples work fine when you're using the
same host, but as soon as the client moves to a remote location, all the
examples fail.

This is how it is with my code as well.

Here is an example with some simple code:
::::::::::::::
RMIClient.java
::::::::::::::
import java.rmi.registry.*;

public class RMIClient {
public static void main(String[] args) {
String host = args[0];
int port = Integer.parseInt(args[1]);
if (System.getSecurityManager() == null)
System.setSecurityManager(new SecurityManager());
try {
Registry r = LocateRegistry.getRegistry(host, port);
ServerIface s = (ServerIface) r.lookup("RMIServerName");
System.out.println(s.hello());
} catch (Exception e) {
e.printStackTrace();
}
}
}
::::::::::::::
RMIServer.java
::::::::::::::
import java.rmi.RemoteException;
import java.rmi.registry.*;
import java.rmi.server.UnicastRemoteObject;

public class RMIServer extends UnicastRemoteObject implements ServerIface {
protected RMIServer() throws RemoteException { super(); }
public static void main(String[] args) {
String host = args[0];
int port = Integer.parseInt(args[1]);
if (System.getSecurityManager() == null)
System.setSecurityManager(new SecurityManager());
try {
Registry r = LocateRegistry.getRegistry(host, port);
r.bind("RMIServerName", new RMIServer());
} catch (Exception e) {
e.printStackTrace();
}
}
public String hello() throws RemoteException {
return "Hello World";
}
}
::::::::::::::
ServerIface.java
::::::::::::::
import java.rmi.Remote;
import java.rmi.RemoteException;

public interface ServerIface extends Remote {
public abstract String hello() throws RemoteException;
}

I also have a wide open security policy file:
::::::::::::::
policy
::::::::::::::
grant {
permission java.security.AllPermission;
};

Here's my commands:

rmiregistry &
java -Djava.security.policy=policy RMIServer localhost 1099 &
java -Djava.security.policy=policy RMIClient localhost 1099

The problem is with the next command from a remote host:

java -Djava.security.policy=policy RMIClient adam 1099
java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
java.net.ConnectException: Connection refused
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)
at $Proxy0.hello(Unknown Source)
at RMIClient.main(RMIClient.java:12)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
....


I tried switching server and clients, (and had to change ports) but
without any success.

I think the registry is OK, I make a simple ListRMI program using
Naming.list() to view the registry entries.

Can anyone help -- not just for me -- but for all the rest looking for a
definitive answer to what's going on and how to fix it?
Thanks!

.



Relevant Pages

  • RE: Remote Desktop/Term. Serv information leakage
    ... connection settings for your given connection, ... ability to have your hard drive mapped on the remote host. ... They asked us to test if the isolated network was adequately ...
    (Pen-Test)
  • Re: Remote Desktop and Spy Sweeper...Definite Problem
    ... They neglected to include the 2nd link from Webroot, which was for the actual registry update. ... I was disturbed to be having problems getting a consistent remote connection. ...
    (microsoft.public.windowsxp.work_remotely)
  • RE: PCanywhere: security of it and operation over DSL/cable modems
    ... I have had PC Anywhere running over a VPN connection quite happily. ... However I have setup laptops for remote support running PC Anywhere before, ... By giving both the host and remote PC Anywhere packages the ... have any better encryption on the communication link then definitely use it. ...
    (Security-Basics)
  • remote desktop wont work...TS MVP suggested I post here.
    ... I can't seem to get remote desktop to work. ... The terminal server service is not started and won't start on the host. ... Cable internet connection with router installed and enabled for port 3389 ... "The net logon service on the local computer started and then stopped. ...
    (microsoft.public.windowsxp.work_remotely)
  • Re: remote connection not always available with PCAnywhere, XP
    ... I don't know what's happening with PCAnywhere, ... Have you considered trying Remote Desktop instead--to see whether it works ... > server for the business software is our PCanywhere host. ... > is that PCAnywhere is waiting to make a connection. ...
    (microsoft.public.windowsxp.work_remotely)