Salve,
sto cercando di capire il funzionamento della connessione RMI tra client e server.
Praticamente ho questo fatto questo server per la gestione remota di uno stack
RMIServer.java
Stack.javacodice:package rmiserver; import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; public class RMIServer { public static void main(String[] argv) throws Exception { StackImp s = new StackImp(10); Registry reg = LocateRegistry.createRegistry(1099); reg.rebind("xyz", s); System.out.println("RMI Server pronto...."); System.out.println("In attesa della richiesta..."); } }
codice:package rmiserver; import java.rmi.*; public interface Stack extends Remote { public void push(int p) throws RemoteException; public int pop() throws RemoteException; }
StackImp.java
I seguenti, invece, sono i file che compongono il clientcodice:package rmiserver; import java.rmi.*; import java.rmi.server.*; public class StackImp extends UnicastRemoteObject implements Stack { private int tos, data[], size; public StackImp() throws RemoteException { super(); } public StackImp(int s) throws RemoteException { super(); size = s; data = new int[size]; tos = -1; } public void push(int p) throws RemoteException { tos++; data[tos] = p; } public int pop() throws RemoteException { int temp = data[tos]; tos--; return temp; } }
RMIClient.java
Stack.javacodice:package rmiclient; import java.rmi.*; public class RMIClient { public static void main(String[] argv) throws Exception { String url = "rmi://localhost/"; Stack s = (Stack) Naming.lookup(url+"xyz"); s.push(25); // System.out.println("Push: " + s.push(25)); System.out.println("Pop: " + s.pop()); } }
Quando lancio il server in esecuzione riesco a vedere entrambi i messaggicodice:package rmiclient; import java.rmi.*; public interface Stack extends Remote { public void push(int p) throws RemoteException; public int pop() throws RemoteException; }
Quando lancio il client, invece, mi viene sollevata questa eccezionecodice:System.out.println("RMI Server System.out.println("In attesa della richiesta...");
Dove sto sbagliando?codice:Exception in thread "main" java.rmi.UnmarshalException: error unmarshalling return; nested exception is: java.lang.ClassNotFoundException: rmiserver.Stack (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 rmiclient.RMIClient.main(RMIClient.java:19) Caused by: java.lang.ClassNotFoundException: rmiserver.Stack (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 Java Result: 1
Grazie

Rispondi quotando


