Reputation: 2703
I'm going through the tutorial at sun's website, try to use RMI.
But when I try to start the server I get this error:
ComputeEngine exception:
java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:1099" "connect,resolve")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:372)
at java.security.AccessController.checkPermission(AccessController.java:559)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1051)
at java.net.Socket.connect(Socket.java:574)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.<init>(Socket.java:425)
at java.net.Socket.<init>(Socket.java:208)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:146)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:340)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at engine.ComputeEngine.main(ComputeEngine.java:31)
Can someone advice on how to remedy this? How do I get rid of this exception, how do i fix it?
This is where i get the exception (where i drew the arrow on the right of the line):
package engine;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import compute.Compute;
import compute.Task;
public class ComputeEngine implements Compute {
public ComputeEngine() {
super();
}
public <T> T executeTask(Task<T> t) {
return t.execute();
}
public static void main(String[] args) {
if (System.getSecurityManager() == null) {
System.setSecurityManager(new SecurityManager());
}
try {
String name = "Compute";
Compute engine = new ComputeEngine();
Compute stub =
(Compute) UnicastRemoteObject.exportObject(engine, 0);
Registry registry = LocateRegistry.getRegistry();
registry.rebind(name, stub); <<<<<------
System.out.println("ComputeEngine bound");
} catch (Exception e) {
System.err.println("ComputeEngine exception:");
e.printStackTrace();
}
}
}
and finally this is how i start my program:
I'll leave further pertinent information that may be of use underneath:
This is the file ~/.server_policy:
grant codeBase "file:/home/jenia/Documents/eclipse/workspace/asti01/bin" {
permission java.security.AllPermission;
};
This is the tree of the project directory:
/home/jenia/Documents/eclipse/workspace/asti01$ tree
.
├── bin
│ ├── client
│ │ ├── ComputePi.class
│ │ └── Pi.class
│ ├── compute
│ │ ├── Compute.class
│ │ └── Task.class
│ └── engine
│ └── ComputeEngine.class
└── src
├── client
│ ├── ComputePi.java
│ └── Pi.java
├── compute
│ ├── Compute.java
│ └── Task.java
├── compute.jar
└── engine
└── ComputeEngine.java
this is the tree of the folder ~/public_html
/home/jenia/public_html/
└── classes
├── client
│ └── Pi.class
└── compute.jar
Upvotes: 0
Views: 3518
Reputation: 311055
The answer to your original question is that EOFException in RMI usually results from a SecurityManager problem at the other end. Try it without the codebase and security managers.
The answer to the 2nd version of your question is that the Registry isn't running, and getRegistry() doesn't start it. createRegistry() does.
The answer to the third version of your question is the same as to the first version.
When you get past all this to the next error, which will undoubtedly be ClassNotFoundException
when binding, the solution is to run the Registry with the correct classpath.
When you get past that to the next error, which will undoubtedly be ClassNotFoundException
when looking-up, the solution is to run the client with the correct classpath.
Upvotes: 1
Reputation: 53694
To reiterate @EJP's original comment:
Ignore everything in the tutorial related to configuring/using a SecurityManager. Don't attempt to use remote code loading. These "features" greatly increase the complexity of using rmi and 99% of users don't actually need them.
Upvotes: 1
Reputation: 21923
If your RMI Registry Server is running in Localhost then you should use 127.0.0.1
not 127.0.1.1
Pass in 127.0.0.1
when starting ComputePi
Upvotes: 0