/* JFox, the OpenSource J2EE Application Server
 *
 * Distributable under GNU LGPL license by gun.org
 * more details please visit http://www.huihoo.org/jfox
 */

package org.jfox.system;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.rmi.MarshalledObject;

/**
 * Get a remote Service according the host and port
 *
 * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
 */

public class ServiceLocator {

    public static Object getRemoteObject(InetAddress host, int port) throws IOException, ClassNotFoundException {
        Socket csocket = new Socket(host, port);
        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(csocket.getInputStream()));
        Object obj = in.readObject();
        csocket.close();
        MarshalledObject mobj = (MarshalledObject) javax.rmi.PortableRemoteObject.narrow(obj, MarshalledObject.class);
        return mobj.get();
    }

}
