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

843793Mar 21 2007 — edited May 28 2007
Hi all,

I am having some problems with the RMI and not sure what it is. I am using this RMI service: http://rmijdbc.objectweb.org/. I can setup a sever on a machine and connect to it from a lan. But when i change the connect address to an internet IP address, which should be the same server, i get the exception above. I have forwared the ports to the machine it needs to go to but it will not connect. I was wondering if it is a security setup issuse? or if its just my router being lame and not passing the connection on?

Thanks alot

Scotty

Comments

843793 Mar 21 2007
This could be any number of things:

1) Java security policy configuration

2) Port blocked at the router

3) Port blocked by a software firewall.


Make sure that you can reach this port from the Internet first. A network scanner like nmap could help you do this. If the port is reachable from the outside world, take a look @ your java code / security policy.
843793 Mar 21 2007
There is no software firewall and the router is supposed to be configured to forward the port. I have never set up Java security policy configuration. What do i have to do to change it? and what would i have to change it to?

Scotty
843793 Mar 21 2007
Have you validated that you can reach the port externally with a network scanner?
EJP Mar 21 2007
Have you forwarded the port that appears in the exception message?
843793 Mar 21 2007
I have tried Nmap on the LAN and the port is there, how ever on the internet IP it is not. I think this is because the router is not listining on this port, but when it recives somthing it should pass it on to the server which the makes the connection? And yes the port is forwarded under the "Virtual servers" tab of my router.

Scotty
843793 Mar 21 2007
Sounds like a router misconfiguration, then.
EJP Mar 22 2007
You are aware that the Registry and your remote object don't both necessarily use port 1099? unless you've taken steps to ensure they do ... or have you've exported your remote object on some other specific port that's forwarded in the router?
843793 Mar 22 2007
The server is set to port 30945 and the client tries to connect on this port. The router is supposed to forward the port to the machine where the RMI server is. The client is set to connect on prot 30945, but it doesnt. Should the starndard security policys be enough to allow a connection? If so, then yes, it does sound like the router is being lame.

Scotty
843793 Mar 22 2007
Didn't you say in your post above that the port cannot be reached through the router externally????? Solve this problem first.
843793 Apr 6 2007
Ok, i have fixed the connection issuse. I can now telnet into that port from the outside world, however it now says connection refused to host and gives the IP address of the server (192.168.1.10, which i find odd because this is a private IP). However if i connect using the domain name from inside the LAN it works, but not from the internet. Is there something in the java policy to stop connections from the outside and only accept them from the LAN? if this is so, how do i change it to say it can accept connections?

Thanks alot

Scotty
843793 Apr 11 2007
Hi,
As I just wrote in another post, it is possible that you have opened 1 port but the second port for communication is random. And if you don't specify that port when exporting the objects you will never get thru the firewall.

/Fredrik
843793 Apr 13 2007
@ Ik95jofr,

Ok if that is the case, is there some way to force it to use the same port as the connection is established on? BTW i just did a test using net limiter to see the ports, and as well as using 30945, theres another one 1031. It is highly likely that this is being blocked by the uni. Is there a way to make it use 30945 as the connection back or use say 8080 (the uni's HTTP port, or would that have problem with the proxy server?) Sorry bout all the questions, but i am new to this, and this is the first time i have set this up.

Thanks

Scotty
843793 Apr 16 2007
Hi,
I am not using the same port, I have 2 ports open.
But I guess you can specify them to "be one".

Here is how I do;

Server:
FixedPortRMISocketFactory fsf = new FixedPortRMISocketFactory();
RMISocketFactory.setSocketFactory(fsf);
registry = LocateRegistry.createRegistry(rmiPortConnection);
myServer = new MyClassImpl(databaseDriver, databaseURL.toString(), databaseUser, databasePasswd, log, logClient);
myServer.setFamilyTreeVersion(familyTreeVersion);
TreeSocketFactory tsf = new TreeSocketFactory(rmiHost);
FamilyTree tree = (FamilyTree)UnicastRemoteObject.exportObject(ftServer, rmiPortData,(RMIClientSocketFactory)tsf,(RMIServerSocketFactory)tsf);
Naming.rebind(rmiBinding.toString(), tree);




FixedPortRMISocketFactory:
public class FixedPortRMISocketFactory extends RMISocketFactory implements Serializable {
private static final long serialVersionUID = 7211277855000000000L;

public Socket createSocket(String host, int port) throws IOException {
return new Socket(host, port);
}

public ServerSocket createServerSocket(int port) throws IOException {
port = (port == 0 ? 7898 : port);
return new ServerSocket(port);
}
}



TreeSocketFactory:
public class TreeSocketFactory extends RMISocketFactory implements Serializable {
private static final long serialVersionUID = 7211277855000000000L;
private String host = null;
private ServerSocket serverSocket = null;

public TreeSocketFactory(String h) {
super();

host = h;
}

public Socket createSocket(String h, int port) throws IOException {
return new Socket(host, port);
}

public ServerSocket createServerSocket(int port) throws IOException {
port = (port == 0 ? 7898 : port);
return new ServerSocket(port);
}
}


So as u see, I have 2 socket factory's.
Try this or similar and I think you might get it to work.

/Fredrik
843793 Apr 18 2007
wow..... i understand none of that, buit i found an easier way to make it network. I changed the database from a acces to a MySQl database, not its more secure and works on the net. Thanks for your help anyways, you get the points :P

scotty
EJP Apr 18 2007
@lk95jofr : you don't need to write RMI socket factories just to specify a port number. Have a look at UnicastRemoteObject's constructors and the exportObject() method.
843793 May 28 2007
Hi Scotty,

I just had a similar problem.
The problem was, that the registry was not running.

The code
Registry registry = LocateRegistry.createRegistry(1099);

seems to start the registry and create a registry object.

The code
Registry registry = LocateRegistry.getRegistry();
seems only to be working, if the registry has already been started.
1 - 16
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jun 25 2007
Added on Mar 21 2007
16 comments
795 views