BAD_PARAM in java CORBA

Deadly 提交于 2019-12-23 04:33:39

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!