Lokeshmsit 0 Newbie Poster

i m creating a Client/Server application in which my server and client can be on the same or on different machines but both are under ISP.

My RMI programs:-
-Remote Interface:-

//Calculator.java
public interface Calculator 
extends java.rmi.Remote { 
public long add(long a, long b) 
throws java.rmi.RemoteException; 
 
public long sub(long a, long b) 
throws java.rmi.RemoteException; 
 
public long mul(long a, long b) 
throws java.rmi.RemoteException; 
 
public long div(long a, long b) 
throws java.rmi.RemoteException;
}

Remote Interface Implementation:-

//CalculatorImpl.java
public class CalculatorImpl 
extends 
  java.rmi.server.UnicastRemoteObject 
implements Calculator { 
 
public CalculatorImpl() 
    throws java.rmi.RemoteException { 
    super(); 
} 
 
public long add(long a, long b) 
    throws java.rmi.RemoteException { 
    return a + b; 
} 
 
public long sub(long a, long b) 
    throws java.rmi.RemoteException { 
    return a - b; 
} 
 
public long mul(long a, long b) 
    throws java.rmi.RemoteException { 
    return a * b; 
} 
 
public long div(long a, long b) 
    throws java.rmi.RemoteException { 
    return a / b; 
} 
 
}

Server:-

//CalculatorServer.java
 import java.rmi.Naming;
 import java.rmi.server.RemoteServer;
 public class CalculatorServer {
 
  public CalculatorServer(String IP) 
  {
    try {
 
         Calculator c = new CalculatorImpl();
 
         Naming.rebind("rmi://"+IP+":1099/CalculatorService", c);
        } catch (Exception e) 
          {
            System.out.println("Trouble: " + e);
          }
  }
 
     public static void main(String args[]) {
     new CalculatorServer(args[0]);
   }
}

Client:-

//CalculatorClient.java
 
 import java.rmi.Naming; 
 import java.rmi.RemoteException; 
 import java.net.MalformedURLException; 
 import java.rmi.NotBoundException; 
 
  public class CalculatorClient { 
 
  public static void main(String[] args) { 
    try { 
       Calculator c = (Calculator)Naming.lookup("rmi://"+args[0]+"/CalculatorService"); 
 
        System.out.println( c.sub(4, 3) ); 
        System.out.println( c.add(4, 5) ); 
        System.out.println( c.mul(3, 6) ); 
        System.out.println( c.div(9, 3) ); 
    } 
    catch (MalformedURLException murle) { 
        System.out.println(); 
        System.out.println("MalformedURLException"); 
        System.out.println(murle); 
    } 
    catch (RemoteException re) { 
        System.out.println(); 
        System.out.println("RemoteException"); 
        System.out.println(re); 
    } 
    catch (NotBoundException nbe) { 
        System.out.println(); 
        System.out.println("NotBoundException"); 
        System.out.println(nbe); 
    } 
    catch (java.lang.ArithmeticException ae) { 
        System.out.println(); 
        System.out.println("java.lang.ArithmeticException"); 
        System.out.println(ae); 
    } 
  } 
}

when both Server and client programs are on same machine:-

i start my server program by passing my router static IP address:-192.168.1.35 in args[0] and my server starts...fine.

and by passing the same Static IP address in my Client's args[0] also works fine.

but:-

when both Server and client programs are on different machines:-

now,i m trying to start my Server Program by passing it's public IP address:59.178.198.247 in args[0] so that it can receive call over internet.
but i am unable to start it.

and the following exception occurs:-

Trouble: java.rmi.ConnectException: Connection refused to host: 59.178.198.247;
nested exception is:
    java.net.ConnectException: Connection refused: connect

i think it is due to NAT Problem because i am under ISP.
so,my problem is that how can i start my RMI Server under ISP so that it can receive remote calls from internet????
if it is router related problem then what should i do with my router?????