title: Not able to invoke remote method in RMI communication
body: <p>I am trying to execute one RMI program but i am getting exception when i try to call the remote method from RMI client program. </p>
  
  <p>Server program:</p>
  
  <pre><code>import java.rmi.*;
  import java.rmi.registry.*;
  import java.rmi.server.*;
  
  
  public class Hello extends UnicastRemoteObject implements HelloInterface {
  
      private String message;
  
      public Hello() throws RemoteException{
             int port=1024; 
            Registry registry;
             try{
                registry = LocateRegistry.createRegistry(port);
                registry.rebind("samplermi", this);
                System.out.println ("Server started and listening on port " + port);
  
            }
            catch(RemoteException e){
                System.out.println("remote exception"+ e);
            }
        }
  
        public String sayHi (String name) throws RemoteException {
            message = "Hi .. Welcome " + name;
        return message;
        }
  
  
        public static  void main(String args[]){
            try{
                Hello serverObj = new Hello();
            }
            catch (Exception e){
            e.printStackTrace();
            System.exit(1);
            }
            }
  
  
  }
  </code></pre>
  
  <p>Client Program:</p>
  
  <pre><code>registry=LocateRegistry.getRegistry(serverAddress,serverPort);
            if(registry !=null){
                 String[] availRemoteServices = registry.list();
                for(int i=0;i&lt;availRemoteServices.length;i++){
                    System.out.println("Service " + i + ": " +availRemoteServices[i]);                  
                }           
            }
             rmiServer=(HelloInterface)(registry.lookup("samplermi"));
  
            System.out.println("calling remote method!");
            // call the remote method
            welcomeMsg = rmiServer.sayHi(text);
        System.out.println("Message from server: " + welcomeMsg);
  </code></pre>
  
  <p>I am getting connection exception only at the time of calling the remote method sayHI. It works fine for lookup and listing the service name. </p>
  
  <pre><code>R:\Deptapps\itdm\Sample_RMI&gt;java NewSampleRMIClient
  Getting Registry Object from server!!
  Registry Object Created!!
  Service 0: samplermi
  Services listed successfully!
  
  Look up successful!
  calling remote method!
  
  java.rmi.ConnectException: Connection refused to host; nested exception is:
          java.net.ConnectException: Connection timed out: 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.invoke(Unknown Source)
          at Hello_Stub.sayHi(Unknown Source)
          at NewSampleRMIClient.main(NewSampleRMIClient.java:42)
  Caused by: java.net.ConnectException: Connection timed out: connect
          at java.net.PlainSocketImpl.socketConnect(Native Method)
          at java.net.PlainSocketImpl.doConnect(Unknown Source)
          at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
          at java.net.PlainSocketImpl.connect(Unknown Source)
          at java.net.SocksSocketImpl.connect(Unknown Source)
  </code></pre>
  
  <p>Note: The same program is working correctly when running server in solaris and client from windows. It is not working only when running server in AIX and client from windows.</p>
  
  <p>Kindly can someone help in resolving this issue. I have been trying to fix this issue since 2 days but no use. Please help me!!</p>