利用空闲的时间复习了一下rmi技术:感觉不错。
代码如下:
1.接口:
public interface IHello extends Remote {
public String helloword()throws RemoteException;
public String syssomdebody(String name)throws RemoteException;
}
2。实现类:
@SuppressWarnings("serial")
public class HelloImpl extends UnicastRemoteObject implements IHello {
protected HelloImpl() throws RemoteException {
super();
}
@Override
public String helloword() throws RemoteException {
return "XX你好!";
}
@Override
public String syssomdebody(String name) throws RemoteException {
// TODO Auto-generated method stub
return "你好:"+name+"欢迎!";
}
}
3.服务器端:
public class HelloService {
public static void main(String[] args){
try{
IHello ih=new HelloImpl();
LocateRegistry.createRegistry(8888);
Naming.bind("rmi://localhost:8888/IH", ih);
System.out.println("远程对象绑定成功!");
}catch(Exception e){
e.getMessage();
}
}
}
4.客户端:
public class HelloClient {
public static void main(String[] args)
{
try{
IHello ihl=(IHello)Naming.lookup("rmi://localhost:8888/IH");
System.out.println(ihl.helloword());
System.out.println(ihl.syssomdebody("32222333333333"));
}catch(Exception e){
e.getMessage();
}
}
}