01: /* JFox, the OpenSource J2EE Application Server
02: *
03: * Copyright (C) 2002 huihoo.com
04: * Distributable under GNU LGPL license
05: * See the GNU Lesser General Public License for more details.
06: */
07:
08: package org.huihoo.jfox.service;
09:
10: import java.rmi.MarshalledObject;
11: import java.io.BufferedInputStream;
12: import java.io.ObjectInputStream;
13: import java.io.IOException;
14: import java.net.Socket;
15: import java.net.InetAddress;
16:
17: /**
18: * Get a remote Service according the host and port
19: *
20: * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
21: */
22:
23: public class ServiceLocator {
24:
25: public static Object getRemoteObject(InetAddress host, int port)
26: throws IOException, ClassNotFoundException {
27: Socket csocket = new Socket(host, port);
28: ObjectInputStream in = new ObjectInputStream(
29: new BufferedInputStream(csocket.getInputStream()));
30: Object obj = in.readObject();
31: csocket.close();
32: MarshalledObject mobj = (MarshalledObject) javax.rmi.PortableRemoteObject
33: .narrow(obj, MarshalledObject.class);
34: return mobj.get();
35: }
36:
37: }
|