1

好的,所以我的问题是我正在做一个很像收费的项目。客户端将 ID 发送到第一台服务器,在他成为客户端并连接到第二台服务器后,如果汽车可以通过,他会通过一个过程返回。现在我在 CORBA 中遇到了麻烦(项目最初是在 RMI 中创建的,在其中工作正常)但我在从第一台服务器连接到第二台服务器时遇到了麻烦。有人告诉我,ORB 必须以其他方式初始化,而不是像运行客户端时那样,即 XXXClient -ORBInitialPort 1999。我可以与第一台服务器正常连接,但第二台服务器没有任何进展。这是最终将成为客户端的服务器的代码

import PROApp.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;

import java.util.Properties;

class PROImpl extends PROPOA {
private ORB orb;

public void setORB(ORB orb_val) {
 orb = orb_val; 
  }

  // implement sayHello() method
  public String check1(int number) 
  {
    try{
        if(number > 0 && number <8000) 
        {
            String serverReply2 = "parta";
            serverReply2 = proCarImpl.check2(number);
            System.out.println(serverReply2);
            if(serverReply2.equals("ACK"))
            {
                return "You shall pass";
            }
        else if(serverReply2.equals("NACK"))
            {
                return "You shall not pass, not enought credits";
            }
        else
            {
                return "You're probably not on the list or something went wrong";
            }
    }
    else
     {
        return "Wrong ID number";
     }
     }
     catch (Exception e)
        {
            System.out.println("PROServer is not bound in rmiregistry... Exception:" + e);
        }return "ooups";
  }

  // implement shutdown() method
  public void shutdown() {
    orb.shutdown(false);
  }
}


public class PROServer {

  public static void main(String args[]) {
    try{
  // create and initialize the ORB
  ORB orb = ORB.init(args, null);

  // get reference to rootpoa & activate the POAManager
  POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
  rootpoa.the_POAManager().activate();

  // create servant and register it with the ORB
  PROImpl proImpl = new PROImpl();
  proImpl.setORB(orb); 

  // get object reference from the servant
  org.omg.CORBA.Object ref = rootpoa.servant_to_reference(proImpl);
  PRO href = PROHelper.narrow(ref);

  // get the root naming context
  // NameService invokes the name service
  org.omg.CORBA.Object objRef =
      orb.resolve_initial_references("NameService");
  // Use NamingContextExt which is part of the Interoperable
  // Naming Service (INS) specification.
  NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);

  // bind the Object Reference in Naming
  String name = "project corba";
  NameComponent path[] = ncRef.to_name(name);
  ncRef.rebind(path, href);

  System.out.println("PROServer with name "+ name+ " is up and it's waiting ...");

  // wait for invocations from clients
  orb.run();

        ORB orb = ORB.init(args, null);

        org.omg.CORBA.Object objRef = 
        orb.resolve_initial_references("NameService");
        NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
        String name = "project corba car";
        proCarImpl = PROCarHelper.narrow(ncRef.resolve_str(name));

        System.out.println("Obtained a handle on server object: " + proCarImpl);

} 

  catch (Exception e) {
    System.err.println("ERROR: " + e);
    e.printStackTrace(System.out);
  }

  System.out.println("HelloServer Exiting ...");

  }
}
4

0 回答 0