Results 1 to 5 of 5
  1. #1
    lokeshmsit is offline Member
    Join Date
    Apr 2010
    Posts
    3
    Rep Power
    0

    Question how to start up my RMI server(under ISP) so that it can recieve remote calls ??

    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:-
    Java Code:
    //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:-
    Java Code:
    //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:-
    Java Code:
    //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:-
    Java Code:
    //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 recieve call over internet.
    but i am unable to start it.

    and the following exception occurs:-
    Java Code:
    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 recieve remote calls from internet????

    note:-
    i also think that i can achieve my goals by HTTP Tunneling.
    so,can anybody tell me how to do HTTP Tunneling in my above programs.????

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default

    Did you start the rmiregistry before you started your server?

    kind regards,

    Jos

  3. #3
    lokeshmsit is offline Member
    Join Date
    Apr 2010
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    Did you start the rmiregistry before you started your server?

    kind regards,

    Jos
    yes...

    rmiregistry 1099

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default

    Make your server rebinds using just the name "CalculatorService"; it is only up to the client to name the host where your service is running.

    kind regards,

    Jos

  5. #5
    lokeshmsit is offline Member
    Join Date
    Apr 2010
    Posts
    3
    Rep Power
    0

    Thumbs up

    Quote Originally Posted by JosAH View Post
    Make your server rebinds using just the name "CalculatorService"; it is only up to the client to name the host where your service is running.

    kind regards,

    Jos
    thanx Jos,
    now, i m able to start my rmi server..
    but,now can you tell me how to HTTP tunneling at Client side so that server (listens only on port no. 80 and 21) can able to receive client side calls in the form of HTTP packets.

Similar Threads

  1. start server button
    By gisler in forum Networking
    Replies: 1
    Last Post: 12-03-2009, 12:06 PM
  2. Replies: 1
    Last Post: 06-26-2009, 03:24 PM
  3. Remote SQL Server Connection
    By saso1310 in forum JDBC
    Replies: 2
    Last Post: 05-15-2009, 07:39 AM
  4. connecting to remote SQL server
    By mahasarathi in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 04-04-2009, 06:11 AM
  5. Replies: 0
    Last Post: 03-05-2009, 05:45 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •