wood burning stoves 2.0*
The moose likes Distributed Java and the fly likes Help needed in RMI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Help needed in RMI " Watch "Help needed in RMI " New topic
Author

Help needed in RMI

sandeep iyer
Greenhorn

Joined: Dec 04, 2000
Posts: 13
Dear Friends,
I have written a RMI program where the client
just queries the server and gets a string as reply.
The program compiles fine and all the settings are
proper. The rmic has generated the stubs and skeletons.
But when the server is run, it prints an AccessControl
Exception and then waits. I donot know why this is
happening. I am connected to the internet when I
run the program. Can any one help me in this regard ?
Thanks
Sandeep
asad ali
Greenhorn

Joined: Dec 12, 2000
Posts: 20
The access control access generally happens when there is security permission not granted for certain permission type. You need to provide more information about the error you received to debug the problem.
sandeep iyer
Greenhorn

Joined: Dec 04, 2000
Posts: 13
Dear Asad Ali,
My program is given below. It compiles fine and all stubs and skeletons are generated. I saw in an earlier posting that u must change the security policy. I want to know some details about this. May be specifying "localhost" has a problem.
/* ---------- This is the interface -------------- */
import java.rmi.*;
public interface RMIServer extends Remote{
public String getName() throws RemoteException;
}
/* ------------------------------------------- */
/* ----------- This is interface implementation -------------*/
import java.rmi.*;
import java.rmi.server.*;
public class RMIimpl extends UnicastRemoteObject implements RMIServer{

public RMIimpl() throws RemoteException{
super();
}
public static void main(String []args){
System.setSecurityManager(new RMISecurityManager());
try{
RMIimpl rmi = new RMIimpl();
System.out.println("Server side : Done");
Naming.bind("rmi:///RMIServer", rmi);
System.out.println("Server side : Done");
}catch(Exception ex){ System.out.println(ex); }
}
public String getName() throws RemoteException{
return "My name";
}
}
/* ------------------------------------------ */
/*-------- Client ----------------*/
import java.rmi.*;
public class RMIClient{
private static String strName;
public static void main(String []args){
try{
RMIServer rmiClient = (RMIServer)Naming.lookup("rmi://localhost/RMIServer");
strName = rmiClient.getName();
System.out.println(strName);
}catch(Exception ex){System.out.println(ex);}
}
}
/* ------------------------------------- */
Thanks
Sandeep
asad ali
Greenhorn

Joined: Dec 12, 2000
Posts: 20
Dear Sandeep,
I see that you are installing SecurityManager in your server. One of the errors you might be getting when you start your server is "java.net.SocketPermission". If this error is occuring, the reason is the SecurityManager is restricting your server to accept connections. To make it work, you can create your own policy file. Policy file is an ascii file containing all the permission you wish to grant to your server. Your policy file may look like this
grant {
permission java.net.SocketPermission "localhost", "connect,accept,listen,resolve";
};
If your create an ascii file called 'mypolicy' and put the above grant statement in it, then you can start your server like this
java -Djava.security.policy=mypolicy RMIImpl
The use of policy file will allow your server to accept connections.
You can learn more about policy file by going to the following URL http://java.sun.com/products/jdk/1.2/docs/guide/security/permissions.html
sandeep iyer
Greenhorn

Joined: Dec 04, 2000
Posts: 13
Great help Asad
Thanks a lot
I will contact back soon
Thanks for the lead
Sandeep
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help needed in RMI
 
Similar Threads
How to solve CORBA MARSHAL Exception
RMI * java.net.ConnectException * occurs when client on remote computer
Help in RMI
AccesscontrolException
RMI help