Advertisement
steverobinson

RMI client

Aug 15th, 2011
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. import java.rmi.Naming;
  2. import java.rmi.RemoteException;
  3. import java.rmi.RMISecurityManager;
  4.  
  5. public class RmiClient {
  6. // "obj" is the reference of the remote object
  7. RmiServerIntf obj = null;
  8.  
  9. public String getMessage() {
  10. try {
  11. obj = (RmiServerIntf)Naming.lookup("//localhost/RmiServer");
  12. return obj.getMessage();
  13. } catch (Exception e) {
  14. System.err.println("RmiClient exception: " + e);
  15. e.printStackTrace();
  16.  
  17. return e.getMessage();
  18. }
  19. }
  20.  
  21. public static void main(String args[]) {
  22. // Create and install a security manager
  23. if (System.getSecurityManager() == null) {
  24. System.setSecurityManager(new RMISecurityManager());
  25. }
  26.  
  27. RmiClient cli = new RmiClient();
  28.  
  29. System.out.println(cli.getMessage());
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement