RMI requires 3 components: client, server and a shared remote interface. The shared remote interface defines the client-server contract by specifying the methods a server must implement. The interface must be visible to the server so that it can implement the methods; the interface must be visible to the client so that it knows which methods ("services") the server provides.
Any object implementing a remote interface is destined to take the role of a server. As such, a client-server relationship in which the server can also invoke methods in the client is in fact a server-server relationship. This is termed callback since the server can call back the "client". With this in mind, it is acceptable to use the designation client for the servers that function as such.
The shared remote interface is any interface extending Remote
. An object that functions as a server undergoes the following:
UnicastRemoteObject
which implements Remote
.UnicastRemoteObject
, or explicitly by being passed to UnicastRemoteObject#exportObject
.Registry
or indirectly through Naming
. This is only necessary for establishing initial communication since further stubs can be passed directly through RMI.In the project setup, the client and server projects are completely unrelated, but each specifies a shared project in its build path. The shared project contains the remote interfaces.