Java RMI Demo-- Java RMI 示例
本文给出了一个Java RMI的示例,其中注册过程是使用Registry
本例子包含了共5个文件,分别是HelloClient,Hello,HelloServer,Configur,config.properti
/*Hello.java*/
/*
* Created on 2004-11-10
*
*/
package test.rmi;
import java.rmi.Remote;
import java.rmi.RemoteException;
/**
* @author dogcome
*
*
远程方法调用接口,定义远程调用方法
*/
public interface Hello extends Remote {
String sayHello() throws RemoteException;
}
/*HelloServer*/
/*
* Created on 2004-11-10
*
*/
package test.rmi;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
/**
* @author dogcome
*
*
服务器端,实现了Hello接口中的方法,用于实现远程调用方法的具体业务逻辑
*/
public class HelloServer extends UnicastRemoteObject implements Hello {
String name;
public HelloServer(String s) throws RemoteException {
super();
name=s;
}
public String sayHello() throws RemoteException {
// TODO Auto-generated method stub
return "Hello world!";
}
public static void main(String[
阅读(2671) | 评论(0) | 转发(0) |