/Users/lyon/j4p/src/net/rmi/simpleExample/RmiHelloClient.java
|
1 package net.rmi.simpleExample;
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 RemoteHello rh = null;
10
11 public RmiHelloClient(String location) {
12 rmiUrl = location;
13 try {
14 rh = lookupDelgate();
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
24 private RemoteHello lookupDelgate()
25 throws NotBoundException,
26 java.net.MalformedURLException,
27 RemoteException {
28 RemoteHello rh = (RemoteHello)
29 Naming.lookup(rmiUrl);
30 return rh;
31 }
32
33 public static void main(String args[]) {
34 try {
35 RmiHelloClient rhc =
36 new RmiHelloClient(
37 "rmi://localhost/RemoteHello");
38 rhc.testGetMsg();
39 } catch (RemoteException e) {
40 e.printStackTrace();
41 }
42 }
43
44 private void testGetMsg()
45 throws
46 RemoteException {
47 System.out.println(rh.getMsg());
48 }
49 }
50