当我用 Java 编写客户端-服务器聊天程序时遇到 BAD_PARAM 错误。第一个代码段是服务器
//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();
}
这是我的客户端
//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();
}
我已经启动了我的 orbd 和 Server.java。一切都很好,除了客户。错误是 org.omg.BAD_PARAM vmcid 0x0 次要代码:0 已完成:否,它发生在 Client c = ClientHelper.narrow(obj);
我已经为这个错误苦苦挣扎了 3 天。有什么建议可以解决吗?谢谢你,我真的很感谢你的帮助!