Home Help Center

BiDirectional connection - problem with cast

lukaszg84lukaszg84 Member Lukasz GruszkaOrganization: AGH University of Science and TechnologyProject: VoIP
I got following exception while trying to setup bidirectional connection:
Ice.ObjectPrxHelperBase cannot be cast to voip.ClientPrx
The exception is thrown on server, after client invokes method from slice interface.

Client (C#):
class IceConnectionManager: ClientDisp_
    {

        (...) - implementation of Client from slice

        public void register() {
            Ice.Communicator ic = Ice.Util.initialize();
            // getting server proxy
            Ice.ObjectPrx objPrx = 
                ic.stringToProxy("SomeServer:default -h localhost -p 10000");
            serverPrx = voip.ServerPrxHelper.checkedCast(objPrx);
            if (serverPrx == null)
            {
                throw new Exception();
            }
            // bidirectional
            Ice.ObjectAdapter adapter =
                ic.createObjectAdapterWithEndpoints("Client", "tcp -p 10001");
            Ice.Identity ident = new Ice.Identity();
            ident.name = Ice.Util.generateUUID();
            ident.category = "";
  
            
            adapter.add(this, ident);
            adapter.activate();

            serverPrx.ice_timeout(config.getICETimeout());
            serverPrx.ice_getConnection().setAdapter(adapter);

 EXCEPTION:           serverPrx.register(userId, password, ident);
        }

Server (Java):
public String register(String id, String password, Identity identity,
Current __current) throws AuthenticationFailureException {
    try {
        ObjectPrx prx = __current.con.createProxy(identity);
        System.err.println(prx.getClass());
EXCEPTION:    ClientPrx proxy = ClientPrx.class.cast(prx);
    ...

Comments

  • matthewmatthew NL, CanadaMember Matthew NewhookOrganization: ZeroC, Inc.Project: Internet Communications Engine ✭✭✭
    You should use ClientPrxHelper.uncheckedCast (or checkedCast), not a direct cast. See the Ice manual for full details on the slice to Java mapping.

    Do you also need to create a new communicator like that? 99% of applications only need a single communicator. The most common case where more than one communicator is necessary is an pplication server, such as IceBox.
  • lukaszg84lukaszg84 Member Lukasz GruszkaOrganization: AGH University of Science and TechnologyProject: VoIP
    matthew wrote: »
    You should use ClientPrxHelper.uncheckedCast (or checkedCast), not a direct cast. See the Ice manual for full details on the slice to Java mapping.

    Thanks. it is working right now.
    Do you also need to create a new communicator like that? 99% of applications only need a single communicator. The most common case where more than one communicator is necessary is an pplication server, such as IceBox.

    What do you mean by "single communicator"? The application is some kind of instant messenger - communication is in both sides.

    I have two questions:
    1. Is the timeout set correctly (i.e. in proper place on valid object)?
    serverPrx.ice_timeout(config.getICETimeout());
    

    2. How can I unregister from proxy (i.e. remove bidirectional adapter and release TCP port)?
  • matthewmatthew NL, CanadaMember Matthew NewhookOrganization: ZeroC, Inc.Project: Internet Communications Engine ✭✭✭
    lukaszg84 wrote: »
    What do you mean by "single communicator"? The application is some kind of instant messenger - communication is in both sides.

    Each call to Ice.Util.initialize() creates a new communicator instance. Typically your application should have one communicator instance active at any time.
    I have two questions:
    1. Is the timeout set correctly (i.e. in proper place on valid object)?
    serverPrx.ice_timeout(config.getICETimeout());
    

    No that is incorrect. Proxies are immutable, and cannot be changed. ice_timeout returns a new proxy. This could should be something like:
    serverPrx= serverPrx.ice_timeout(config.getICETimeout());
    
    2. How can I unregister from proxy (i.e. remove bidirectional adapter and release TCP port)?

    Sorry, but this question doesn't really make sense. Proxies are similar to pointers, in that they indirectly refer to an object. However, there is no guarantee that the object to which they refer actually exists. You cannot determine that without invoking on the proxy. If the object does not exist, you'll get an ObjectNotExistException.

    To destroy an ObjectAdapter, you call destroy. That will release any resources occupied by the adapter.

    It seems to me you misunderstand many aspects of Ice. I would spend some quality time with the Ice manual, and the many newsletter articles. In particular, you should read "Proxies" in http://www.zeroc.com/newsletter/issue23.pdf.
Sign In or Register to comment.