xxlali
xxlali

Reputation: 1046

RMI implementation Java

I want to implement a simple RMI application with Java.

Here is my classes;

RMIInterface;

public interface RMIInterface extends Remote
{
     String translate ( String wordInTurkish ) throws RemoteException ;
}

RMIImplementation;

public class RMIImplementation implements RMIInterface
{
    @Override
    public String translate ( String wordInTurkish )
    {
        if ( wordInTurkish.equalsIgnoreCase( "Merhaba" ) )  { return "Hello" ; }
        if ( wordInTurkish.equalsIgnoreCase( "..."     ) )  { return "..."   ; }

        return "Not found in the dictionary" ;
    }
}

RMIServer;

public class RMIServer
{
    public static void main ( String args[] ) throws Exception
    {
         String codebase = "http://localhost:8080/rmi/" ;
         String name     = "RMIInterface"               ;
         System.setProperty( "java.rmi.server.codebase" , codebase ) ;
         RMIImplementation obj  = new RMIImplementation();
         RMIInterface      stub = (RMIInterface) UnicastRemoteObject.exportObject( obj , 0 );
         LocateRegistry.createRegistry(2020).bind(name, stub);
    }
}

RMIClient;

public class RMIClient
{
    public static void main ( String args[] ) throws Exception
    {
        String host = "localhost"    ;
        String name = "RMIInterface" ;       
    }
}

How can I implemet the RMIClient and is there anything wrong in other parts?

Upvotes: 0

Views: 594

Answers (3)

Daniel Wondyifraw
Daniel Wondyifraw

Reputation: 7723

 serverAddress=127.0.0.1
 rmiRegistiry=rmi://127.0.0.1/DanBankServer

 Registry locateServerRegistery = LocateRegistry.getRegistry(serverAddress);
 System.out.println("Server Registery is  been looked up for address: "+rmiRegistiry);
 SekelatonInterface danBankServer = (SekelatonInterface) locateServerRegistery.lookup(serverRmiUrl);

Upvotes: 0

Makky
Makky

Reputation: 17471

RMIInterface remote = (RMIInterface ) 
LocateRegistry.getRegistry("localhost",8080).lookup("RMIInterface");
remote.translate("merhaba");

Upvotes: 1

Evgeniy Dorofeev
Evgeniy Dorofeev

Reputation: 136132

try this

    RMIInterface cl = (RMIInterface) new InitialContext().lookup("rmi://localhost:2020/RMIInterface");
    String res = cl.translate("xxx");

Upvotes: 1

Related Questions