NodeJS callback implementation

gkorovkingkorovkin Member Gin KorovkinOrganization: FreelancerProject: proof of concept

Hi!

I am trying to prototype a few things before using ZeroC RPC framework. Scheme is pretty straightforward. We are having some ServiceFactory, which returns Service, which is providing some functionality and invoke callback on result competition.
Server side is C++ and client side is NodeJS and Java. Java work pretty well - no question here, but I am stuck with Node JS part.

I am creating a listener in JS code and trying to pass it to service. Please see code snippet below(sorry for formatting):
return ic.createObjectAdapter("").then(
function(adapter)
{
var r = adapter.addWithUUID(new CoolResultListenerI());
factory_prx.ice_getCachedConnection().setAdapter(adapter);
console.log(r);
return SRV.CoolResultListenerPrx.checkedCast(r).then(
function(listener_prx)
{
service_prx.SetListener(listener_prx);
service_prx.ApplyValue(42);
});
});

No luck here. Ice is throwing an error with valid ID but strange EP:

Ice::NoEndpointException
proxy: "8d3a083f-5814-40b9-e3f2-a928050e71f9 -t -e 1.1"

When I am trying to create an adapter with local EP(createObjectAdapterWithEndpoints):

Ice::FeatureNotSupportedException
unsupportedFeature: "object adapter endpoints not supported"

After reviewing docs/samples (where no Prx was used but Ice::Identity) can I conclude that this current approach doesn't work with ZeroC ICE ? (at least 3.6.*) version.

Thank you!

ps. Overall test is here https://github.com/gkorovkin/zeroc_js_test/

Best Answer

  • gkorovkingkorovkin Gin KorovkinOrganization: FreelancerProject: proof of concept
    edited July 2017 Accepted Answer

    Sorry for borrowing you - found solution.

                                    var prx = adapter.createProxy(r.ice_getIdentity());
                                    service_prx.SetListener(prx);
                                    service_prx.ApplyValue(42);
    

    But now I have an exception on server side :)
    terminating with uncaught exception of type Ice::NoEndpointException: Reference.cpp:1676: Ice::NoEndpointException:
    no suitable endpoint available for proxy `f2d96ae4-b84a-4697-8463-4b8e6c30b003 -t -e 1.1'

    Could you please help me on that?

Answers

  • gkorovkingkorovkin Member Gin KorovkinOrganization: FreelancerProject: proof of concept
    edited July 2017 Accepted Answer

    Sorry for borrowing you - found solution.

                                    var prx = adapter.createProxy(r.ice_getIdentity());
                                    service_prx.SetListener(prx);
                                    service_prx.ApplyValue(42);
    

    But now I have an exception on server side :)
    terminating with uncaught exception of type Ice::NoEndpointException: Reference.cpp:1676: Ice::NoEndpointException:
    no suitable endpoint available for proxy `f2d96ae4-b84a-4697-8463-4b8e6c30b003 -t -e 1.1'

    Could you please help me on that?

  • xdmxdm La Coruña, SpainAdministrators, ZeroC Staff Jose Gutierrez de la ConchaOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff

    Hi Gin,

    The problem is that you are sending a proxy to the server and that defeats the purpose of using a bidirectional connection see Bidirectional Connections page in Ice manual.

    You want to instead send the Identity of the CoolResultListener object and let the server create the proxy using the connection.

    Take a look at the bidirectional demos:

    JS Client

    return communicator.createObjectAdapter("").then(
        function(adapter)
        {
            //
            // Create a callback receiver servant and add it to
            // the object adapter.
            //
            var r = adapter.addWithUUID(new CallbackReceiverI());
    
            //
            // Set the connection adapter.
            //
            proxy.ice_getCachedConnection().setAdapter(adapter);
    
            //
            // Register the client with the bidir server.
            //
            return server.addClient(r.ice_getIdentity());
        });
    

    C++ Server

    void
    CallbackSenderI::addClient(const Identity& ident, const Current& current)
    {
        IceUtil::Monitor<IceUtil::Mutex>::Lock lck(*this);
    
        cout << "adding client `" << _communicator->identityToString(ident) << "'"<< endl;
    
        CallbackReceiverPrx client = CallbackReceiverPrx::uncheckedCast(current.con->createProxy(ident));
        _clients.insert(client);
    }
    
  • gkorovkingkorovkin Member Gin KorovkinOrganization: FreelancerProject: proof of concept

    Thanks, Jose!

    Correct me if I wrong:

    • IDL file declared properly
    • Stubs and code generated with no errors or warnings

    But there is no possibility to use this declared semantic using JavaScript bindings?

  • xdmxdm La Coruña, SpainAdministrators, ZeroC Staff Jose Gutierrez de la ConchaOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff

    The only way that your C++ server can call to your JavaScript client is using a bidirectional connection.

Sign In or Register to comment.