Home Help Center

Ice for JavaScript : to get interface from other interface

hdtorreschdtorresc Member David TorresOrganization: diateamProject: network simulation
Hi, I'm new in Ice for JavaScript and I have a question. I have the following file .ice :
#pragma once
module Demo {
	struct Info{
		string str = "String in struct Info";
	};

	interface Master{
		string getMasterString();
	};

	interface Printer{
		void printString(string s);
		string getTest();
		Info getInfo();
		Master* getMaster();
	};
};

I'm attempting to use the "getMasterString" function which belongs to the "Master" interface from other interface ("Printer").

I can retrieve the "Master" but I can't retrieve the string returned by the function "getMasterString".

In the Client.js (after creating the session), I do :
function runWithSession(router, session)
{ 
    var proxy = communicator.stringToProxy("printer -t:tcp -h localhost -p 10000");
    var printer = Demo.PrinterPrx.uncheckedCast(proxy)

    Ice.Promise.all(
	printer.getMaster().then(
	    function(result){
		masterPrx = Demo.MasterPrx.uncheckedCast(result);   
		//console.log(masterPrx.getMasterString().toString());

		masterPrx.getMasterString().then(
		    function(str){
			console.log(str);
		    },
		    function(ex){
			console.log("fail : "+ex);
		    }
		)
		//return result;
	    }
	)/*.then(
	    function(master){
		return master.getMasterString().then(
		    function(str){
			console.log("str : "+str);
		    },
		    function(ex){
			console.log(ex);
		    }
		)       
	    }
	)*/
    );
}

And the result of running the client is :
This Client accepts any user-id / password combination.
user id : user
password : pass
fail : Ice::CommunicatorDestroyedException
    ice_cause: "undefined"

I've attached the files (client, server, config server, config glacier, and .ice).

Comments

  • xdmxdm La Coruña, SpainAdministrators, ZeroC Staff Jose Gutierrez de la ConchaOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    in runWithSession you must return the promise returned by Ice.Promise.all, otherwise finally will be executed as runWithSession queue the promises with Ice.Promise.all and finally method will be invoked and destroy the communicator.

    You need something like:
    function runWithSession(router, session)
    { 
        var proxy = communicator.stringToProxy("printer -t:tcp -h localhost -p 10000");
        var printer = Demo.PrinterPrx.uncheckedCast(proxy)
    
        return Ice.Promise.all(
    ....
    
  • hdtorreschdtorresc Member David TorresOrganization: diateamProject: network simulation
    Thanks, it works. :)
  • mesmes CaliforniaAdministrators, ZeroC Staff Mark SpruiellOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    One other minor comment. There's no need for this line:
    masterPrx = Demo.MasterPrx.uncheckedCast(result);
    

    The call to getMaster returns a MasterPrx value.

    Mark
Sign In or Register to comment.