/Users/lyon/j4p/src/net/rmi/armi/RmiHelloClient.java

1    package net.rmi.armi; 
2     
3    import java.rmi.Naming; 
4    import java.rmi.NotBoundException; 
5    import java.rmi.RemoteException; 
6     
7    public class RmiHelloClient { 
8        private String rmiUrl = null; 
9        private RemoteHelloInterface remoteHelloInterface = null; 
10    
11       public RmiHelloClient(String location) { 
12           rmiUrl = location; 
13           try { 
14               remoteHelloInterface = lookupRemoteHelloInterface(); 
15           } catch (NotBoundException e) { 
16               e.printStackTrace(); 
17           } catch (java.net.MalformedURLException e) { 
18               e.printStackTrace(); 
19           } catch (RemoteException e) { 
20               e.printStackTrace(); 
21           } 
22       } 
23       public RemoteHelloInterface getRemoteHelloInterface() { 
24           return remoteHelloInterface; 
25       } 
26    
27       private RemoteHelloInterface lookupRemoteHelloInterface() 
28               throws NotBoundException, 
29               java.net.MalformedURLException, 
30               RemoteException { 
31           RemoteHelloInterface rh = (RemoteHelloInterface) 
32                   Naming.lookup(rmiUrl); 
33           return rh; 
34       } 
35    
36       public static void main(String args[]) { 
37           try { 
38               RmiHelloClient rhc = 
39                       new RmiHelloClient( 
40                               "rmi://172.16.11.105/RemoteHello"); 
41               RemoteHelloInterface rhi = rhc.getRemoteHelloInterface(); 
42               String ans = rhi.getMsg(); 
43               rhi.testGetMsg(); 
44               System.out.println(ans); 
45           } catch (RemoteException e) { 
46               e.printStackTrace(); 
47           } 
48       } 
49       public String getMsg() throws RemoteException { 
50           return remoteHelloInterface.getMsg(); 
51       } 
52    
53       public void testGetMsg() 
54               throws 
55               RemoteException { 
56           System.out.println(remoteHelloInterface.getMsg()); 
57       } 
58   } 
59