I have a school project with RMI. I tried to write a small "Hello World" program, but I can't make it work.

I've tried to modified the policies and change the way I start rmiregistry, but nothing works... Does anyone have met this problem before?

Link to my code here. It's suppose to work on localhost:1099

I just started the registry with rmiregistry in the terminal, at the root of the project

Error code : Error on server : java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:1099" "connect,resolve") [...] at HelloServer.main(HelloServer.java:15)

Code HelloServer.java :

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class HelloServer {
    public static void main(String[] args) {
        try {
            if (System.getSecurityManager() == null)
                System.setSecurityManager(new SecurityManager()); //Defini Security manager
            //System.setProperty("java.security.policy","file:./default.policy");
            //LocateRegistry.createRegistry(1099);
            HelloImp h = new HelloImp("Hello World!"); //Créer l'objet distant implemente
            Hello h_stub = (Hello) UnicastRemoteObject.exportObject(h, 0);
            Registry registry = LocateRegistry.getRegistry(1099); //Récupère le registre
            registry.bind("Hello1", h_stub); //Ajoute objet distant au registre
            System.out.println("Server ready");
        } catch (Exception e) {
            System.err.println("Error on server : " + e);
            e.printStackTrace();
        }
    }
}```
0

There are 0 best solutions below