Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: RMI connection issue

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default RMI connection issue

    Joined this forum 48hrs ago...I've been trying to run an RMI application from the client side but i've not been successful at doing that. The general concept of RMI (distributed application) is that the server side of the application registers a server object with an RMI registry. This happened successfully with my server application. I'm testing the entire application on my local system for now i.e the server and client part all reside on the same computer. I'm connecting both ends of the application by opening two command prompt side by side with the RMI registry console in between them. Syntactically, there are no problems with the programs because both successfully compiled. Infact it's a basic RMI program in which the client program calls a sayHello() method and a greeting message is returned to the client. I have a feeling that the problem is more of external to the code itself i.e. IP referencing by the system an so on. I stuck to the default port of 1099. I followed the required steps (correctly) to get the application running but when it comes to running the client end to connect to the server, i kept receiving this same message. ConnectException.....refused to host:127.0.0.1

    i followed the directives/advice i got from other forums but the error persisted. The directive i followed include
    1 referencing the rmi.server.hostname env variable when running the server program
    2 editing the hosts folder under \etc folder to ensure that RMI registry is indeed sticking to the localhost

    The same exception persisted. I'll appreciate if someone assist with effective advice on the way out. The application is being run on windows 7.

    Olakunle Oni


  2. #2
    Member vigneshwaran's Avatar
    Join Date
    Nov 2012
    Location
    Chennai, TamilNadu
    Posts
    35
    My Mood
    Cheerful
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default Re: RMI connection issue

    Hi here i give a simple RMI program

    Compile

    1. javac RmiServer.java

    2. rmic RmiServer

    3. javac RmiClient.java



    - Execution

    1. (at one host,) java RmiServer

    2. (at another host) java RmiClient <server�fs address> 3232 <message text>

    - The source codes

    ReceiveMessageInterface.java

     
        import java.rmi.*;
     
    public interface ReceiveMessageInterface extends Remote
     
    {
     
        �@�@�@�@�@�@�@void receiveMessage(String x) throws RemoteException;
     
    �@�@�@�@�@�@}
     
     
     
    RmiServer.java
     
     
     
    import java.rmi.*;
     
    import java.rmi.registry.*;
     
    import java.rmi.server.*;
     
    import java.net.*;
     
     
     
    public class RmiServer extends java.rmi.server.UnicastRemoteObject
     
    implements ReceiveMessageInterface
     
    {
     
        int      thisPort;
     
        String   thisAddress;
     
        Registry registry;    // rmi registry for lookup the remote objects.
     
     
     
        // This method is called from the remote client by the RMI.
     
        // This is the implementation of the �gReceiveMessageInterface�h.
     
        public void receiveMessage(String x) throws RemoteException
     
        {
     
            System.out.println(x);
     
        }
     
     
     
        public RmiServer() throws RemoteException
     
        {
     
            try{
     
                // get the address of this host.
     
                thisAddress= (InetAddress.getLocalHost()).toString();
     
            }
     
            catch(Exception e){
     
                throw new RemoteException("can't get inet address.");
     
            }
     
    thisPort=3232;  // this port(registry�fs port)
     
            System.out.println("this address="+thisAddress+",port="+thisPort);
     
            try{
     
            // create the registry and bind the name and object.
     
            registry = LocateRegistry.createRegistry( thisPort );
     
                registry.rebind("rmiServer", this);
     
            }
     
            catch(RemoteException e){
     
            throw e;
     
            }
     
        }
     
     
     
        static public void main(String args[])
     
        {
     
            try{
     
            RmiServer s=new RmiServer();
     
        }
     
        catch (Exception e) {
     
               e.printStackTrace();
     
               System.exit(1);
     
        }
     
         }
     
    }

    RmiClient.java


    import java.rmi.*;
    import java.rmi.registry.*;
    import java.net.*;
     
    public class RmiClient
    {
        static public void main(String args[])
        {
           ReceiveMessageInterface rmiServer;
           Registry registry;
           String serverAddress=args[0];
           String serverPort=args[1];
           String text=args[2];
           System.out.println("sending "+text+" to "+serverAddress+":"+serverPort);
           try{
               // get the �gregistry�h
               registry=LocateRegistry.getRegistry(
                   serverAddress,
                   (new Integer(serverPort)).intValue()
               );
               // look up the remote object
               rmiServer=
                  (ReceiveMessageInterface)(registry.lookup("rmiServer"));
               // call the remote method
               rmiServer.receiveMessage(text);
           }
           catch(RemoteException e){
               e.printStackTrace();
           }
           catch(NotBoundException e){
               e.printStackTrace();
           }
        }
    }

  3. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: RMI connection issue

    Thanks vigneshwaran for your post to the issue i have with RMI connection. But after running the server and client programs locally, I still got java.rmi.UnknownHostException from the client program after supplying host address, port (as retrieved from the server program) and string message as command line arguments when running the client program. The only change i made to the program you posted was that i used the default RMI registry port of 1099 in the programs. I'll appreciate any further assistance in resolving this problem...

    --- Update ---

    Thanks vigneshwaran for your post to the issue i have with RMI connection. But after running the server and client programs locally, I still got java.rmi.UnknownHostException from the client program after supplying host address, port (as retrieved from the server program) and string message as command line arguments when running the client program. The only change i made to the program you posted was that i used the default RMI registry port of 1099 in the programs. I'll appreciate any further assistance in resolving this problem...

  4. #4
    Member vigneshwaran's Avatar
    Join Date
    Nov 2012
    Location
    Chennai, TamilNadu
    Posts
    35
    My Mood
    Cheerful
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default Re: RMI connection issue

    I think the port number making problem in connection. check in your browser with localhost/1099

  5. #5
    Junior Member
    Join Date
    Oct 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: RMI connection issue

    hi vigneshwaran i've still not rectified the java.rmi.UnknownHostException. The suggestion you gave in the last message is unclear to me...i.e I think the port number making problem in connection. check in your browser with localhost/1099. Can give me more details?

Similar Threads

  1. RMI application connection issue
    By progkay7 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 21st, 2013, 05:35 AM
  2. Replies: 1
    Last Post: December 21st, 2012, 10:35 AM
  3. Replies: 12
    Last Post: September 3rd, 2011, 07:07 AM
  4. Replies: 0
    Last Post: March 26th, 2011, 11:07 AM
  5. Java and db2 connection issue
    By sukhpal48806 in forum JDBC & Databases
    Replies: 2
    Last Post: March 1st, 2011, 12:07 PM