JRMITest.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package jrmitest;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author lisanhu-v570
*/
public class JRMITest {
private static final PrintStream out=System.out;
private static final BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) {
System.setSecurityManager(new RMISecurityManager());
try {
Test client=(Test)Naming.lookup("rmi://localhost:3333/obj");
System.out.println(client.getStr());
} catch (NotBoundException ex) {
Logger.getLogger(JRMITest.class.getName()).log(Level.SEVERE, null, ex);
} catch (MalformedURLException ex) {
Logger.getLogger(JRMITest.class.getName()).log(Level.SEVERE, null, ex);
} catch (RemoteException ex) {
Logger.getLogger(JRMITest.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
Test.java
package jrmitest;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Test extends Remote {
public String getStr() throws RemoteException;
}
TestImpl.java
package jrmitest;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class TestImpl extends UnicastRemoteObject implements Test {
public TestImpl() throws RemoteException{
}
public String getStr() throws RemoteException {
return "hello world";
}
}
Server.java
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.rmi.AlreadyBoundException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
public class Server {
private static final PrintStream err=System.err;
private static final int PORT=3333;