Help with java RMI, how to use the rebind method and do lookup with the client class?

1

I am doing a job in college where I feel lost. I do not know how to indicate the server with the rebind method and make lookup with the client class. I would like you to look at the code I am writing to see if I am on the right track and teach how to use rebind , lookup and indicate study materials. Thanks in advance.

Statement of work:

  

You should describe and build a simple system using RMI technology to inform the customer of the current date and time.

     

Based on the interface, build a client that does the lookup for a service provided by the server, using JNDI. This service should return the date and time properly formatted. The client then prints the information to the console.

Interface InterfaceServidorDataEHora :

package javaee_tp1;
import java.rmi.Remote;
import java.rmi.RemoteException;

public interface InterfaceServidorDataEHora extends Remote
{
    public String getHoraData() throws RemoteException;
}

Class ServidorDataEHora :

package javaee_tp1;
import java.rmi.Remote.*;
import java.rmi.RemoteException;
import java.rmi.server.*;
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;

public class ServidorDataEHora extends UnicastRemoteObject implements InterfaceServidorDataEHora
{
    public ServidorDataEHora() throws RemoteException
    {
        System.out.println("ServidorDataHora iniciado... :)");
    }

    @Override
    public String getHoraData() throws RemoteException 
    {
        GregorianCalendar atual = new GregorianCalendar(); 
        SimpleDateFormat formatacao = new SimpleDateFormat("dd' de 'MMMMM' de 'yyyy' - 'HH':'mm'h'");
        return formatacao.format(atual.getTime());
    }
}

Class RegistradorServidor :

package javaee_tp1;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class RegistradorServidor 
{
    public static void main(String[] args) 
    {
        System.out.println("Registrando Servidor no RMI.....");
        try 
        {
            Naming.rebind("ServidorDataEHora_0", new ServidorDataEHora());
        } catch (RemoteException | MalformedURLException ex) {
            System.out.println("Ocorreu um erro de registro \n"+ex.toString());
        }
    }
}

I have not yet written the client class since I think there is something wrong in the classes above.

    
asked by anonymous 15.08.2016 / 15:22

0 answers