欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

一个完整的Java RMI通讯的例子 博客分类: SorLib javarmidemo例子 

程序员文章站 2024-03-11 23:51:56
...
完整的代码,请参考附件。
服务器端:
public class RmiUserServiceImpl extends UnicastRemoteObject implements
		RmiUserService {

	UserService service = new UserServiceImpl();

	public RmiUserServiceImpl() throws RemoteException {
	}

	private static final long serialVersionUID = -7138363701504022490L;

	public void create(String username, String password) throws RemoteException {
		service.create(username, password);
	}

	public User login(String username, String password) throws RemoteException {
		return service.login(username, password);
	}

	public static void main(String[] args) throws RemoteException, MalformedURLException, AlreadyBoundException {
		LocateRegistry.createRegistry(1099);
		Naming.bind("rmi://localhost:1099/UserService", new RmiUserServiceImpl());
		System.out.print("Service start");
	}

}


客户端:
public class Client {

	public static void main(String[] args) throws MalformedURLException, RemoteException, NotBoundException {
		RmiUserService service = (RmiUserService) Naming
				.lookup("rmi://localhost:1099/UserService");
		//service.create("new_user_01", "new_user_01");
		System.out.println(service.login("new_user_01", "new_password_01"));
	}

}
  • rmi.zip (4.1 KB)
  • 下载次数: 28