Reprint Address: http://6221123.blog.51cto.com/6211123/1112619 Click Open link
The second development of RMI network programming How to build a distributed Java RMI program based on JDK1.5 2013-01-09 15:59:47 Tags: JAVA distributed network programming JDK1.5 RMI original works, allow reprint, reprint, please be sure to hyperlink form to indicate the original Origin, author information and this statement. Otherwise, legal liability will be held. http://6221123.blog.51cto.com/6211123/1112619
This is based on the JDK1.5 RMI program to build, simpler to say is a HelloWorld rmi.
1. This is based on JDK1.5, saving tedious manual compilations (generating piles and skeletons). Not like the RMI before 1.4.
2. Here is the client and server side of the two programs, distributed in two separate programs, not the same package below. is truly distributed.
3. Here is not too much elaboration principle, this is just a hello world.
OK, here are the steps:
1. Create a server-side project in Eclipse. Then, create an interface that is the definition of the method you want to open to the client side. It is called: Usermanagerinterface, and must inherit the remote interface.
Package dataserver.rmi.stub; Import Java.rmi.Remote; Import java.rmi.RemoteException; Import Dataserver.rmi.bean.Account; Public interface Usermanagerinterface extends remote{public String getusername () throws remoteexception; Public account Getadminaccount () throws remoteexception; }
2. In order to prove how easy it is to "object-oriented" or "seamlessly pass Java object" in RMI, we need to define an account class that is a bean that must implement the implements serializable serialization interface. This is a serializable object that can be transferred between client and server.
package dataserver.rmi.bean; import java.io.serializable; Public class Account implements Serializable,Cloneable{ /** * */ private static final long serialVersionUID = -1858518369668584532L; private String username; private String password; public string getusername () { return username; } public void setusername (string username) { this.username = username; } public string getpassword () { return password; } public void SetPassword (String password) { this.password = password; }
}
3. At this point, you need to implement the interface you have already opened:
Package dataserver.rmi; Import java.rmi.RemoteException; Import Dataserver.rmi.bean.Account; Import Dataserver.rmi.stub.UserManagerInterface; public class Usermanagerimpl implements Usermanagerinterface {public Usermanagerimpl () throws RemoteException {