package interview.rmi;
import java.rmi.Remote;
import java.rmi.RemoteException;
/**
* 1 : , :
*/
public interface HelloInterface extends Remote
{
public String sayHello() throws RemoteException;
}
package interview.rmi;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
/**
* 2 : ,
* : UnicaseRemoteObject
*
*
*/
public class HelloImpl extends UnicastRemoteObject implements HelloInterface
{
public HelloImpl() throws RemoteException
{
super();
}
public String sayHello() throws RemoteException
{
return "hllo";
}
}
package interview.rmi;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
/**
* :
*
*
*/
public class RMIServer
{
public static void main(String[] args) throws RemoteException,
MalformedURLException
{
// rmiregistry
LocateRegistry.createRegistry(1099);
HelloInterface hello = new HelloImpl();
//
Naming.rebind("//localhost/hello", hello);
}
}
package interview.rmi;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
/**
* :
*
*
*/
public class RMIClient
{
public static void main(String[] args) throws MalformedURLException,
RemoteException, NotBoundException
{
HelloInterface hello = (HelloInterface) Naming
.lookup("//localhost/hello");
System.out.println(hello.sayHello());
}
}