RMI provides the solution of communication between Java processes. For building a RMI Server/Client Application, below steps are considered:
1. define the Remote interfaces extends from java.rmi.Remote
these interfaces will also be provided to client.
note: all remote interfaces throw java.rmi.RemoteException
2. implement the remote interfaces, the implementation classes also extend java.rmi.server.UnicastRemoteObject to export the remote objects.
3. use java.rmi.Naming binds names with remote objects
4. execute rmic to generate stub and skeleton classes based on the remote implementation classes. it seems should be under the "classes" directory instead of "src"
5. on the client side, we should obtain the remote interfaces and stub classes, then look up the remote objects by java.rmi.Naming and convert to the given interfaces. Then we can invoke the remote methods as local ones.
6. for achieve callback functionality, we can program in this way:
6.1 implement client as RMI server as well
6.2 pass client to Server as a listener
6.2 on the RMI server side, invoke methods of listener anytime
本文详细介绍了如何使用Java远程方法调用(RMI)来实现进程间的通信。具体步骤包括定义远程接口、实现这些接口、使用Naming绑定名称与远程对象等。此外,还介绍了如何在客户端查找并调用远程方法,以及实现回调功能的方法。
531

被折叠的 条评论
为什么被折叠?



