RMI SocketPermission exception
i'm working on RMI code
when i wrote the simple Hello program client and server
and made policy file for poth , then when i run the server it throws exception
java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
and here is the server code
import java.net.SocketPermission;
import java.rmi.*;
import java.rmi.server.*;
import javax.naming.*;
import javax.naming.spi.NamingManager;
/**
*
* @author Bingo
*/
public class helloServer
{
/** Creates a new instance of helloServer */
public helloServer()
{
}
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
// TODO code application logic here
if(System.getSecurityManager()==null)
{
System.setProperty("java.security.policy", "Server.policy");
System.setSecurityManager(new RMISecurityManager());
}
try
{
System.out.println("Constructing Hello implementation...");
helloImp hellObj = new helloImp();
System.out.println("Binding hello to registry...");
Context namingContext = new InitialContext();
namingContext.bind("rmi:HelloService",hellObj);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
and the policy file is
grant
{
permission java.security.AllPermission;
permission java.net.SocketPermission "*:1024-65535", "connect,resolve";
};
so if any ony can help me
[1636 byte] By [
Bishoya] at [2007-10-2 14:41:25]

the server is worked and didn't throw exception but only when i made this change to it
import java.net.SocketPermission;
import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
import javax.naming.*;
import javax.naming.spi.NamingManager;
/**
*
* @author Bingo
*/
public class helloServer
{
/** Creates a new instance of helloServer */
public helloServer()
{
}
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
// TODO code application logic here
//if(System.getSecurityManager()==null)
//{
//System.setProperty("java.security.policy", "Server.policy");
//System.setSecurityManager(new RMISecurityManager());
//}
try
{
LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
System.out.println("Constructing Hello implementation...");
helloImp hellObj = new helloImp();
System.out.println("Binding hello to registry...");
Context namingContext = new InitialContext();
namingContext.rebind("rmi:HelloService",hellObj);
//Naming.rebind("rmi://127.0.0.1:1095/HelloService",hellObj);
System.out.println("Binding hello to registry complete...");
}
catch(Exception e)
{
e.printStackTrace();
}
}
but when running the client code it throws another exception telling me that access is denied to 127.0.0.1:1099
import java.io.IOException;
import java.net.Socket;
import java.rmi.*;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.*;
import javax.naming.*;
/**
*
* @author Bingo
*/
public class HelloClient
{
/** Creates a new instance of HelloClient */
public HelloClient()
{
}
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
// TODO code application logic here
if(System.getSecurityManager()==null)
{
System.setProperty("java.security.policy","Client.policy");
System.setSecurityManager(new RMISecurityManager());
}
String URL = "rmi://localhost:1099/";
try
{
hello helloObj =(hello)Naming.lookup(URL + "/HelloService");
System.out.println(helloObj.sayHello());
}
catch(Exception e)
{
e.printStackTrace();
}