问题
I'm encountering the BAD_PARAM error when I program the Client-Server Chat program in Java. The first code segment is the Server
//Server.java
try {
ORB orb = ORB.init(args, null);
POA poa = POAHelper.narrow(orb
.resolve_initial_references("RootPOA"));
poa.the_POAManager().activate();
ServerImpl s = new ServerImpl(port);
System.out.println(port);
org.omg.CORBA.Object obj = poa.servant_to_reference(s);
Server r = ServerHelper.narrow(obj);
// get reference to root naming context
org.omg.CORBA.Object ns = orb
.resolve_initial_references("NameService");
NamingContextExt nc = NamingContextExtHelper.narrow(ns);
// bind the Object Reference in Naming
String name = "Chat";
NameComponent path[] = nc.to_name(name);
nc.rebind(path, r);
System.out.println("Waiting for clients ... ");
orb.run();
} catch (Exception e) {
e.printStackTrace();
}
And this is my Client side
//Client.java
try {
ORB orb = ORB.init(args, null);
// get reference to root naming context
org.omg.CORBA.Object ns = orb
.resolve_initial_references("NameService");
NamingContextExt nc = NamingContextExtHelper.narrow(ns);
// lookup name
String name = "Chat";
org.omg.CORBA.Object obj = nc.resolve_str(name);
Client c = ClientHelper.narrow(obj);
} catch (Exception e) {
//System.err.println(e.getMessage());
e.printStackTrace();
}
I started my orbd and the Server.java already. Everything is good except for the Client. The error is org.omg.BAD_PARAM vmcid 0x0 minor code: 0 completed: No and it happens at the line Client c = ClientHelper.narrow(obj);
I've been struggling with this bug for 3 days. Any suggestions to fix it? Thank you, I really appreciate your helps!
回答1:
The problem is that you are binding a Server
object into the Name Service within your server code, but then your client code tries to narrow that to a Client
type. Those types are incompatible.
Change your client code to do this instead:
Server s = ServerHelper.narrow(obj);
You don't need two separate IDL interfaces for client and server. Just create one that the server implements, and have the client call it.
来源:https://stackoverflow.com/questions/19443206/bad-param-in-java-corba