Results 1 to 2 of 2

Thread: RMI question

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

    Default RMI question

    Hi
    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.net.InetAddress;
    
    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,java.io.Serializable 
    {
        Registry registry;
        
        public Object Perform(Execute inObject,Object inParm) throws RemoteException{
           return (inObject.run(inParm));
        }
        
        public PowerServiceServer () throws RemoteException
        {
            super();
            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
            bi.multiply(bi);
    
            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;
    import java.io.*;
    
    //
    //
    // PowerServiceClient
    //
    //
    public class PowerServiceClient 
    {
    	public static void main(String args[]) throws Exception
    	{
    		// Check for hostname argument
    		
    
    		// Assign security manager
    		if (System.getSecurityManager() == null)
    		{
    			System.setSecurityManager
    			(new RMISecurityManager());
    		}
    
    		// Call registry for PowerService
    		PowerService service = (PowerService) Naming.lookup
    			("rmi://" + args[0] + "/PowerService");
    	        cal c1=new cal();
                    Integer i1=new Integer(90);
                    System.out.println(service.Perform(c1,i1).toString());
                    //System.out.println(service.power(10,20).toString());
    
    		
    			
    		
    	}
    
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Quote Originally Posted by alvandrood View Post
    Hi
    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, 09:49 AM
  2. question
    By ayoood in forum Java Software
    Replies: 6
    Last Post: 07-07-2008, 02:32 PM
  3. question
    By zizou147 in forum New To Java
    Replies: 13
    Last Post: 07-04-2008, 08:05 PM
  4. Need help on this question
    By Deon in forum New To Java
    Replies: 3
    Last Post: 01-27-2008, 04:58 PM
  5. JNI question
    By javaplus in forum New To Java
    Replies: 0
    Last Post: 12-24-2007, 11: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
  •