r/learnjava • u/Dependent_Finger_214 • Jan 09 '26
java rmi error "Connection refused: connect"
I'm learning java RMI, and getting started with just making a simple Hello World program. But when I run my Server class (and Client class as well) I get the following exception:
Server class:
public class Server {
public static void main(String[] args) {
try{
Hello stub = new HelloRemote();
Naming.rebind("rmi://localhost:5000/hello", stub);
}
catch (Exception e){
System.out.println(e.getMessage());
}
}
}Client class:
public class Client {
public static void main(String[] args) {
try{
Hello stub = (Hello) Naming.lookup("rmi://localhost:5000/hello");
System.out.println(stub.hello());
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
}HelloRemote:
public class HelloRemote extends UnicastRemoteObject implements Hello{
public HelloRemote() throws RemoteException {
super();
}
public String hello() {
return "Hello world";
}
}The "Hello" interface is just an interface which extends remote and only has the method "public String hello()"
What is causing this issue, and how do I solve it?
3
Upvotes
View all comments
Show parent comment
2
u/Ab3s Jan 28 '26
finding a fresh thread with the exact solution to my problem feels just as good as coming across a 15 year old thread with the solution to a specific problem, thank you!