Results 1 to 2 of 2

Thread: RMI question

  1. #1
    alvandrood is offline Member
    Join Date
    Aug 2008
    Rep Power

    Default RMI question

    I have created a simple RMI example for practice , that work, but I have found out that both client side and server side must have the same package name
    for example if server side is part of W1 package then client side package name must to be W1 too (not essentially same server side package) that means that if client side package name is W2 then they can't communicate .
    My question is am I right , do two side must have the same package name ?

    at follow is my codes :

    PHP Code:
    package w1;
    import java.math.BigInteger;
    import java.rmi.RMISecurityManager;
    import java.rmi.RemoteException;
    import java.rmi.registry.LocateRegistry;
    import java.rmi.registry.Registry;
    import java.rmi.server.UnicastRemoteObject;
    public class PowerServiceServer   extends UnicastRemoteObject 
    implements PowerService, 
        Registry registry;
        public Object Perform(Execute inObject,Object inParm) throws RemoteException{
           return (;
        public PowerServiceServer () throws RemoteException
            registry = LocateRegistry.createRegistry( 3060 );
            registry.rebind("PowerService", this); 
        // Calculate the square of a number
        public BigInteger square ( int number ) 
        throws RemoteException
            String numrep = String.valueOf(number);
            BigInteger bi = new BigInteger (numrep);
            // Square the number
            return (bi);
        // Calculate the power of a number
        public BigInteger power ( int num1, int num2)
        throws RemoteException
            String numrep = String.valueOf(num1);
            BigInteger bi = new BigInteger (numrep);
    	bi = bi.pow(num2);
    	return bi;
        public static void main ( String args[] ) throws Exception
            // Assign a security manager, in the event that dynamic
    	// classes are loaded
            if (System.getSecurityManager() == null)
                System.setSecurityManager ( new RMISecurityManager() );
            // Create an instance of our power service server ...
            PowerServiceServer svr = new PowerServiceServer();
            // ... and bind it with the RMI Registry
            //Naming.bind ("PowerService", svr);
            System.out.println ("Service bound....");
            System.out.println (InetAddress.getLocalHost().toString());


    PHP Code:
    package w1;
    import java.rmi.*;
    import java.rmi.Naming;
    // PowerServiceClient
    public class PowerServiceClient 
    	public static void main(String args[]) throws Exception
    		// Check for hostname argument
    		// Assign security manager
    		if (System.getSecurityManager() == null)
    			(new RMISecurityManager());
    		// Call registry for PowerService
    		PowerService service = (PowerService) Naming.lookup
    			("rmi://" + args[0] + "/PowerService");
    	        cal c1=new cal();
                    Integer i1=new Integer(90);

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power


    Quote Originally Posted by alvandrood View Post
    My question is am I right , do two side must have the same package name ?
    Isn't it the interface (PowerService) that has to be in the same package? Not the other bits?

Similar Threads

  1. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 08:49 AM
  2. question
    By ayoood in forum Java Software
    Replies: 6
    Last Post: 07-07-2008, 01:32 PM
  3. question
    By zizou147 in forum New To Java
    Replies: 13
    Last Post: 07-04-2008, 07:05 PM
  4. Need help on this question
    By Deon in forum New To Java
    Replies: 3
    Last Post: 01-27-2008, 03:58 PM
  5. JNI question
    By javaplus in forum New To Java
    Replies: 0
    Last Post: 12-24-2007, 10:18 AM

Posting Permissions

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