Home  >  Forum  >  Core Java
Post New Query

java.rmi.ConnectException: Connection refused to host- Java RMI


joined on
October 13,2014
Asked on July 30,2015
I have created a rmi in java code using  eclipse ide. i have created the it in 3 phase but throws some error . any can help me. my all code and error is given below
First code is an interface that extends remote. Second code is a class that implements myremote and third code is client class that call the all code.
 1- MyRemote.java

      public interface MyRemote extends Remote {
 public String sayHello() throws RemoteException;

 }
2- MyRemoteImpl.java

         public class MyRemoteImpl extends UnicastRemoteObject implements MyRemote{

public String sayHello() {
return "Server say, 'Hello'";
}
public MyRemoteImpl() throws RemoteException{
}
public static void main(String[] args) {
try {
MyRemote service = new MyRemoteImpl();
Naming.rebind("RemoteHello", service);
} catch (Exception ex) {
ex.printStackTrace();
}
}

}

3- MyRemoteClient.java

        public class MyRemoteClient {
     public static void main(String[] args) {
new MyRemoteClient().go();
}
public void go() {
try {
MyRemote service = (MyRemote)  Naming.lookup("rmi://127.0.0.1/RemoteHello");
String s = service.sayHello();
System.out.println(s);
} catch (Exception ex) {
ex.printStackTrace();
}
}

}

Error is :

      1-     
       java.rmi.ConnectException: Connection refused to host: 192.168.8.102; nested exception is: 
java.net.ConnectException: 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)

2-
        java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested           exception is: 
  java.net.ConnectException: 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.lookup(Unknown Source)
at java.rmi.Naming.lookup(Unknown Source)

Anyone have any idea?

Write Answer









Copyright ©2017 concretepage.com, all rights reserved |Privacy Policy | Contact Us