Ciao, sto studiando l'RMI per l'università. Ho scritto un semplice esempio, credo sia corretto ma non riesco a capire come eseguirlo.
Credo di eseguire male l'rmiregistry... Si parla di rmic e cose varie ma non ho ben capito.
Dato che è una giornata che cerco la soluzione ho pensato di chiedere aiuto.

Questo è il messaggio di errore che appare quando eseguo il programma.
jhgsf.jpg

Spero che il codice sia chiaro.


codice:
import java.rmi.Remote;
import java.rmi.RemoteException;


public interface Validate extends Remote
{
    public boolean val(String riga) throws RemoteException;
}




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


public class Rmi
{
    public Rmi(){}


    public static void main(String args[])
    {
        try {
            Registry reg = LocateRegistry.getRegistry();
            Validate stub = (Validate) reg.lookup("Validate");


            if(stub.valid("ciao") == true){
                    System.out.println("OK");
            }else{
                    System.out.println("NO");
            }


        }catch (Exception e) {
            System.err.println("Client exception: " + e.toString());
            e.printStackTrace();
        }
    }
}





codice:
package rmix;




import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;


public class Impl implements Validate
{
    public Impl(){}




    public boolean valid(String riga)
    {
        if(riga.length() <= 4 ){
            return true;
        }else{
            return false;
        }
    }




    public static void main(String args[])
    {   
        try
        {
            Impl obj = new Impl();
            Validate stub = (Validate) UnicastRemoteObject.exportObject(obj, 0);


            Registry registry = LocateRegistry.getRegistry();
            registry.rebind("Validate", stub);


            System.out.println("Server ready (CTRL-C quits).");
        }
        catch(Exception e)
        {
                e.printStackTrace();
        }
    }
}

Non riesco proprio a capire cosa non va...