public class Hello extends Java.rmi.server.UnicastRemoteObject implements helloin{
Public Hello () throws remoteexception{
Super ();
}
Public String SayHello () throws remoteexception{
return "hello,world!";
}
public static void Main (string[] args) {
System.setsecuritymanager (New Java.rmi.RMISecurityManager ());
try{
Start the RMI registration program on the command-line before executing the server-side program: Start Rmiregistry
Client program:
Import java.rmi.*;
Import java.rmi.registry.*;
public class helloworld{
public static void Main (string[] args) {
System.setproperty ("Java.security.policy", "Client.policy");
System.setsecuritymanager (New Java.rmi.RMISecurityManager ());
try{
Helloin hi= (Helloin) naming.lookup ("//fengl/hello");
for (int i=0;i<10;i++) {
System.out.println (Hi.sayhello ());
}
}
catch (Exception e) {
E.printstacktrace ();
}
}
}
Use Rmic Hello to generate stub and skeleton class before executing the client program, which
is actually the underlying implementation of the remote call.
Finally, execute the Java Helloworld console to print out the Hello,world, successfully invoked.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.