Archived
This forum has been archived. Please start a new discussion on GitHub.
Determine port number from an IceInternal::ProxyHandle<T> in C++
in Help Center
How can this be done?
If I can't, can I print a IceInternal::ProxyHandle<T> to std::cout like I can in ruby?
If I can't, can I print a IceInternal::ProxyHandle<T> to std::cout like I can in ruby?
0
Comments
-
The proxy API let you access the endpoint and connection info, the connection is only available if the proxy is associated with a connection.
Check the proxy API in the docs https://doc.zeroc.com/display/Ice/Proxy+Methods
Here is some sample codeIce::ObjectPrx proxy = communicator()->propertyToProxy("Hello.Proxy"); // // Get the info of associated endpoints // Ice::EndpointSeq endpoints = proxy->ice_getEndpoints(); for(Ice::EndpointSeq::const_iterator i = endpoints.begin(); i != endpoints.end(); ++i) { Ice::IPEndpointInfoPtr info = Ice::IPEndpointInfoPtr::dynamicCast((*i)->getInfo()); if(info) { cerr << "type: " << info->type() << " host: " << info->host << " port: " << info->port << endl; } } // // checkedCast to force a new connection // HelloPrx twoway = HelloPrx::checkedCast(proxy); // // Now access the connection info // Ice::ConnectionPtr conn = twoway->ice_getCachedConnection(); if(conn) { Ice::IPConnectionInfoPtr info = Ice::IPConnectionInfoPtr::dynamicCast(conn->getInfo()); if(info) { cerr << "localAddress: " << info->localAddress << " localPort: " << info->localPort << "\n" << "remoteAddress: " << info->remoteAddress << " remotePort: " << info->remotePort << endl; } }
0 -
Thanks Jose,
I tried to use this bit:// // Get the info of associated endpoints // Ice::EndpointSeq endpoints = proxy->ice_getEndpoints(); for(Ice::EndpointSeq::const_iterator i = endpoints.begin(); i != endpoints.end(); ++i) { Ice::IPEndpointInfoPtr info = Ice::IPEndpointInfoPtr::dynamicCast((*i)->getInfo()); if(info) { cerr << "type: " << info->type() << " host: " << info->host << " port: " << info->port << endl; } }
but (I guess because we're using Ice 3.3.0) this doesn't compile. I changed it as follows but this causes a core:Ice::EndpointSeq endpoints = proxy->ice_getEndpoints(); for(Ice::EndpointSeq::const_iterator i = endpoints.begin(); i != endpoints.end(); ++i) { cout << (*i)->toString() << endl; }
Pete0 -
It is difficult to know without seeing the crash stack trace, can you post one?
You should also consider updating to the latest release0