Java CORBA中的BAD_PARAM [英] BAD_PARAM in java CORBA
问题描述
当我用Java编写客户端-服务器聊天程序时遇到BAD_PARAM错误.第一个代码段是服务器
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();
}
这是我的客户端
//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);行上.
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);
我已经为这个错误苦苦挣扎了3天.有什么建议可以解决吗?谢谢,我非常感谢您的帮助!
I've been struggling with this bug for 3 days. Any suggestions to fix it? Thank you, I really appreciate your helps!
推荐答案
问题是您正在将Server
对象绑定到服务器代码中的名称服务中,但是随后您的客户端代码尝试将其范围缩小到Client
类型.这些类型不兼容.
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);
对于客户端和服务器,您不需要两个单独的IDL接口.只需创建一个由服务器实现的文件,然后让客户端调用它即可.
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.
这篇关于Java CORBA中的BAD_PARAM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!