The RMI remote method invocation is a communication mechanism between computers that use remote objects to call each other to achieve communication between the two parties. With this mechanism, an object on one computer can invoke an object on another computer to obtain remote data. RMI is the backbone of enterprise JavaBean and a convenient way to build distributed Java applications. In the past, TCP/IP Sockets communication is the main means of remote communication, but this development method does not use an object-oriented approach to development, in the development of such a communication mechanism often makes the programmer feel bored, the RPC (remote Procedure call) came into being, Makes it easier for programmers to invoke remote programs, but RPC is still not well supported in the face of complex messaging, and RPC has failed to achieve object-oriented development patterns.
RMI Development Steps:
1. First create the remote interface and declare the remote method, note that this is only the interface to achieve communication between the two, need to inherit remote.
2. Develop a class to implement remote interfaces and remote methods, it is worth noting that the implementation class needs to inherit UnicastRemoteObject.
3. Compile the file through the Java command, register the service with the Java-server command, and start the remote object.
4. Finally the client looks for the remote object and calls the remote method.
Java instance:
1. First create a model layer for the service, note that because this object requires remote transport, you must inherit serializable.
2. Create the remote interface Personservice, and note that the remote interface needs to inherit remotes.
3. Establish Personserviceimpl to implement the remote interface, note that this is a remote object implementation class, need to inherit unicastremoteobject.
4. Establish server side, register RMI communication port and communication path on server side, then communicate javac command to compile file, register service through Java-server command.
5. Do after I establish the client to test, note that the RMI path called must be server configuration consistent.
JAVA Remote Object