/* JFox, the OpenSource J2EE Application Server
 *
 * Copyright (C) 2002 huihoo.com
 * Distributable under GNU LGPL license
 * See the GNU Lesser General Public License for more details.
 */

package org.huihoo.jfox.service;

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

/**
 * 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();
  }

}
