日期:2014-05-17 浏览次数:20670 次
/*
* 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);
}
}
}
package jrmitest;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Test extends Remote {
public String getStr() throws RemoteException;
}
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";
}
}
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.rmi.AlreadyBoundException;
import java.rmi.Naming;
im