barapapupi
barapapupi

Reputation: 19

Having errors on Java RMI Server/Client Implementation

I'm currently following a small tutorial for RMI on another thread, here is the link! The problem I'm having is that if I put all the classes on the same project(I'm using Netbeans) then it works flawlessly, but on real life the client and the server are usually different machines, so when I try to put the Client on a different project and Implement the same interface and SomeStruct class then I get the following error:

java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: rmiserver.SomeInterface (no security manager: RMI class loader disabled)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:101)
at clientrmi.SomeClient.main(SomeClient.java:17)
Caused by: java.lang.ClassNotFoundException: rmiserver.SomeInterface (no security manager: RMI class loader disabled)
at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:556)
at java.rmi.server.RMIClassLoader$2.loadProxyClass(RMIClassLoader.java:646)
at java.rmi.server.RMIClassLoader.loadProxyClass(RMIClassLoader.java:311)
at sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalInputStream.java:255)
at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1559)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1515)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1774)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
... 3 more

and if I Implement the following code on the client :

if(System.getSecurityManager() == null) {
    System.setSecurityManager(new SecurityManager());
}

then I get the following error:

java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:1234" "connect,resolve")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:457)
at java.security.AccessController.checkPermission(AccessController.java:884)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1051)
at java.net.Socket.connect(Socket.java:584)
at java.net.Socket.connect(Socket.java:538)
at java.net.Socket.<init>(Socket.java:434)
at java.net.Socket.<init>(Socket.java:211)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148)
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:342)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:101)

Any ideas on how to fix this? Any input is truly appreciated!

Upvotes: 0

Views: 394

Answers (1)

KSK
KSK

Reputation: 158

I think your problem is that you need a total of 3 projects:

  1. First project contains the interface.
  2. Second project contains the Server and add the first project as one of the libraries.
  3. Third project contains the Client and add the first project as one of the libraries.

The key is that the client and server projects each have to have the interface (the same interface) inside the project.

Your error: java.lang.ClassNotFoundException: rmiserver.SomeInterface (no security manager: RMI class loader disabled) Says that it can't find your class: SomeInterface. I don't think the Security Manager is your real problem.

Hope that helps.

Upvotes: 1

Related Questions