Archived

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

retrieve proxy id

Hi there

I was wondering if there is an easy way to retrieve Proxy ids?

I am currently toying with the demos supplied with the Ice documentation and would like to do the following. While passing a clientproxy to a list on the server I would like to cout the id (used as username) of the proxy. The clientcode is as follows:
//code omitted

int
CallbackClient::run(int argc, char* argv[])
{	
	string username;
	//Enter Username tryblok begin
	try
	{
	    cout << "Enter Username.\n";

	    
	    cout << "Username: " << flush;
	    getline(cin, username);
	}
	catch(const Exception& ex)
	{
	    cerr << ex << endl;
	    return EXIT_FAILURE;
	}
	//Enter Username tryblok end

    PropertiesPtr properties = communicator()->getProperties();
    const char* proxyProperty = "Callback.Client.CallbackServer";
    std::string proxy = properties->getProperty(proxyProperty);
    if(proxy.empty())
    {
	cerr << appName() << ": property `" << proxyProperty << "' not set" << endl;
	
	return EXIT_FAILURE;
    }

    CallbackSenderPrx server = CallbackSenderPrx::checkedCast(communicator()->stringToProxy(proxy));
    if(!server)
    {
	cerr << appName() << ": invalid proxy" << endl;
	
	return EXIT_FAILURE;
    }

    ObjectAdapterPtr adapter = communicator()->createObjectAdapter("Callback.Client");
    Identity ident;
    ident.name = username;
    ident.category = "";
    CallbackReceiverPrx somevarname = CallbackReceiverPrx::uncheckedCast(adapter->add(new CallbackReceiverI, ident)); 

	
    adapter->activate();
    server->ice_connection()->setAdapter(adapter);

    server->addClient(somevarname);

//code omitted

on the server:
void
CallbackSenderI::addClient(const CallbackReceiverPrx& proxy, const Current& current)
{
    //pseudocode begin:
    // cout the username providet as [COLOR="Red"]ident[/COLOR]on the clientside:
    //CallbackReceiverPrx somevarname = CallbackReceiverPrx::uncheckedCast(adapter->add(new CallbackReceiverI, [COLOR="Red"]ident[/COLOR])); 
	//pseudocode end

_clients.push_back(proxy);

}

Comments

  • matthew
    matthew NL, Canada
    For support please fill out your signature information as described in this post http://www.zeroc.com/vbulletin/showthread.php?t=1697
  • I did, but after my initial post :o
  • bernard
    bernard Jupiter, FL
    You can extract the Ice::Identity from a proxy with ice_getIdentity(), e.g. prx->ice_getIdentity().

    Since Ice 3.0.0, you can also "print" a proxy, e.g. cout << "My proxy: " << prx << endl.

    Cheers,
    Bernard
  • sweet 'n easy:D

    thanx
  • hi,steepLearningC,
    It seemed that you made some mistakes when using bi-dir connection. The ice document (page 916 , version 3.0.0)has given very detailed explanations about this. please refer to it.
    You can get the identity via ice_getIdentity(), but you can't print it with
    cout << "My proxy: " << prx << endl
    since in your bi-dir case the proxy is a type of "fixed" ,which doesn't support unmarshalling.
    I think Benard must overlook some lines of you codes:) .

    Cheers
    OrNot