Archived

This forum has been archived. Please start a new discussion on GitHub.

Retrieve server proxy on client side(JS) from router (Glacier 2)

Hello,

We are building a web based ICE client on Glacier2. We have not configured any session manager. Our server side component does not extend from Session as well. We are trying to get a proxy object of the server side like below but we are unsuccesfull. How do we get a server proxy so that we can call operations on it ? Could someone please help.
    var RouterPrx = Glacier2.RouterPrx;
    var ServerSideObjPrx = ServerSideObjPrx ;

       var router =  "Glacier2/router:ws -p 5063 -h " + hostname + " -r /testws";
        var id = new Ice.InitializationData();
        id.properties = Ice.createProperties();
        id.properties.setProperty("Ice.Default.Router", router);
        communicator = Ice.initialize(id);
        
      Ice.Promise.try(
            function()
            {
                return RouterPrx.checkedCast(communicator.getDefaultRouter());
            }
        ).then(
            function(r)
            {
            
                router = r;

                //
                // Create a session with the Glacier2 router.
                //
              
                return router.createSession("test", "test");
             [B][COLOR=#FF0000]  // this returns a plain Glacier2 session[/COLOR][/B]
            }
        ).then(
            function(session)
            {                
              var objProxy=(ServerSideObjPrx .uncheckedCast(session));
              [COLOR=#FF0000][B]//objProxy here is not ServerSideObjPrx[/B][/COLOR]
            }
        ).exception(
       function(){
         });


Thanks.

Cheers,
Murthy

Comments

  • benoit
    benoit Rennes, France
    Hi Murthy,

    If you do not configure a session manager, the createSession call should return a nil proxy object.

    To create a proxy to an Ice object hosted by a server behind Glacier2, you can create the proxy from a string as shown in the example below:
    function(session)
    {
        var proxy = ServerSideObjPrx .uncheckedCast(communicator.stringToProxy("MyServerSideObjectId:tcp -p 12345 -h 192.168.1.25"));
        ...
    }
    

    Here, we assume the server side object identity is MyServerSideObjectId and that the server where this object is hosted is running on a machine with the IP 192.168.1.25 and listening on port 12345. That is, you must provide the endpoint information of the back-end server. The JavaScript client won't try to connect to this endpoint if the Glacier2 router session is established, instead it will forward the invocation to Glacier2 which will take care of calling on the back-end server.

    While the solution above is simple, it requires the client to know the backend server endpoints which isn't ideal.

    To avoid this, I recommend to implement and configure a session manager and implement a simple session interface whose role is to provide this proxy. For example, your session interface could just be the following:
    // Slice
    
    module Sample
    {
    
    interface ServerSideIntf
    {
    ...
    };
    
    interface Session
    {
       ServerSideIntf* getServerSideObj();  
    };
    
    };
    

    Then your JavaScript client would just need to cast the session proxy provided by Glacier2 and call the method to get the server side object proxy:
    // JavaScript
    
    function(session)
    {
        return Sample.SessionPrx.uncheckedCast(session).getServerSideObj();
    },
    function(proxy)
    {
    ...
    }
    

    Let us know if you need more information on this.

    Cheers,
    Benoit.
  • Thank you for the detailed explanation Benoit :) We were wondering the same earlier as to why the Client should know about backend end points. We will try to configure and implement a session manager as you suggested.

    Another question: We are building a streaming application where an ICE server pushes the data (via websockets) to the Clients using callbacks. Earlier for a simple prototype using call backs, we were able to see great performance. However if the server is now calling back via Glacier, the performance appears to be significantly affected. Does this extra step now (server to galcier to client) have any impact on the performance ? There seems to be some buffering in between now. Could you please give some more info on this ?

    Thanks.

    Cheers,
    Murthy
  • benoit
    benoit Rennes, France
    Hi,

    See Glacier2 Request Buffering. You could try disabling the buffering to see if it makes a difference for your application. The addition of Glacier2 will impact performances and in particular the latency since a request isn't sent directly anymore to the web application. I don't think it should affect much the throughput performances however. Do you have an idea of how much it affects the performances for your application? Does it affect the latency or the throughput?

    Cheers,
    Benoit
  • Thank you Benoit,

    We were buffering the requests from servers to clients which was affecting the latency. We are able to improve the performance without buffering the requests.

    Cheers,
    Murthy