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 :
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());
}
}
-----------------------------------------------------------------
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());
}
}

