0

我想用 Java 实现一个简单的 RMI 应用程序。

这是我的课;

RMI接口;

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

RMII实施;

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" ;
    }
}

RMI服务器;

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);
    }
}

RMI客户端;

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

如何实现 RMIClient 以及其他部分有什么问题吗?

4

3 回答 3

1

尝试这个

    RMIInterface cl = (RMIInterface) new InitialContext().lookup("rmi://localhost:2020/RMIInterface");
    String res = cl.translate("xxx");
于 2013-06-12T13:48:48.520 回答
1
RMIInterface remote = (RMIInterface ) 
LocateRegistry.getRegistry("localhost",8080).lookup("RMIInterface");
remote.translate("merhaba");
于 2013-06-12T13:55:01.423 回答
0
 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);
于 2013-07-01T11:39:22.070 回答