import java.rmi.*;
public interface HelloWorldInterface extends Remote
{
public String ToString() throws RemoteException ; ;
}import java.rmi.server.*;
import java.rmi.*;
public class HelloWorld extends UnicastRemoteObject implements HelloWorldInterface
{
public HelloWorld () throws RemoteException
{
super();
}
public String ToString()
{
return "Hello World";
}
}import java.rmi.*;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class ServerMain
{
public static void main(String []args)
{ try
{
HelloWorld aa=new HelloWorld();
LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
Naming.rebind("Hello",aa);
System.out.println("RegistryOk");
}
catch(Exception e)
{
System.out.println("RegistryFail");
System.out.println(e.getMessage());
}
}
}
import java.rmi.*;
public class ClieMain
{
public static void main(String []args)
{
try
{
HelloWorldInterface aa=(HelloWorldInterface)Naming.lookup("Hello");
System.out.println(aa.ToString());
}
catch(Exception e)
{
System.out.println("Load Error \n"+e.getMessage());
}
}
}
public interface HelloWorldInterface extends Remote
{
public String ToString() throws RemoteException ; ;
}import java.rmi.server.*;
import java.rmi.*;
public class HelloWorld extends UnicastRemoteObject implements HelloWorldInterface
{
public HelloWorld () throws RemoteException
{
super();
}
public String ToString()
{
return "Hello World";
}
}import java.rmi.*;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class ServerMain
{
public static void main(String []args)
{ try
{
HelloWorld aa=new HelloWorld();
LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
Naming.rebind("Hello",aa);
System.out.println("RegistryOk");
}
catch(Exception e)
{
System.out.println("RegistryFail");
System.out.println(e.getMessage());
}
}
}
import java.rmi.*;
public class ClieMain
{
public static void main(String []args)
{
try
{
HelloWorldInterface aa=(HelloWorldInterface)Naming.lookup("Hello");
System.out.println(aa.ToString());
}
catch(Exception e)
{
System.out.println("Load Error \n"+e.getMessage());
}
}
}
能不能介绍一下如何构建这样的系统
比如:
客户机,服务器各自的职责,功能?
客户机,与服务器是否一直通过rmi协议通信?
是否有常用的设计模式哪里有c/s架构的例子系统。
等等。。