It's not a secret anymore!
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes rmi connection refused if not 1099 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "rmi connection refused if not 1099" Watch "rmi connection refused if not 1099" New topic

rmi connection refused if not 1099

YungSheng Chang
Ranch Hand

Joined: Jul 28, 2003
Posts: 44
I believe somebody else meets this too, but I couldn't find related post.
To start rmi server programatically, I use LocateRegistry.createRegistry(portNum);
my code:
Hello h = new Hello("Steve");
Everything works successfully for 1099(including client calling the method), however, if the port is not 1099, let's say 1098, the following exception occures at Naming.rebind.
I am using java version 1.4.2_01. Thank you for the advice!!
Exception in thread "main" java.rmi.ConnectException: Connection refused to hos
:; nested exception is: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
at sun.rmi.server.UnicastRef.newCall(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Unknown Source)
at Test.main(
Caused by: Connection refused: connect
at Method)
at Source)
at Source)
at Source)
at Source)
at Source)
at<init>(Unknown Source)
at<init>(Unknown Source)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown
... 7 more

I play Java for fun.<br /> <br />SCJP / SCJD / SCWCD / SCBCD
Ken Krebs
Ranch Hand

Joined: Nov 27, 2002
Posts: 451
The code you show creates a new registry but uses the default registry, not the new one.
After creating the registry, you have to get a reference to it and then use it to perform the binding as in the following example:

kktec<br />SCJP, SCWCD, SCJD<br />"What we observe is not nature itself, but nature exposed to our method of questioning." - Werner Heisenberg
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
The createRegistry() method does have a return value, for precisely this purpose:

"I'm not back." - Bill Harding, Twister
YungSheng Chang
Ranch Hand

Joined: Jul 28, 2003
Posts: 44
Yes, it works, thank you all.
In fact, we were taught to use network socket to write project in school. That may be quite different from you guys. Well I have to say RMI is more straightforward though.
Yap, if you ever implement the "network whiteboard" project, we may go to the same school.
It is sorta covered in the JavaRanch Style Guide.
subject: rmi connection refused if not 1099
It's not a secret anymore!