Archived

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

Query hostname based on connection information

Hi,

Ice 3.5.1

Configuration:
XYZ.Proxy=XYZ:tcp -h localhost -p 10000

At runtime from the client, what is best way to get the "just" the hostname (not the ip address) and port?

Regards,
Vishwa

Comments

  • benoit
    benoit Rennes, France
    Hi,

    In C++, you would do something along those lines to print out the host/port specified in the proxy endpoint:
    // C++
    Ice::ObjectPrx proxy = communicator->propertyToProxy("XYZ.Proxy");
    Ice::EndpointSeq seq = proxy->ice_getEndpoints();
    if(!seq.empty())
    {
         Ice::EndpointInfoPtr info = seq[0]->getInfo();
         Ice::IPEndpointInfoPtr ipInfo = Ice::IPEndpointInfoPtr::dynamicCast(info)
         std::cout << "host = " << ipInfo->host << ", port = " << ipInfo->port << std::endl;
    }
    

    Cheers,
    Benoit.
  • What would be the C# version? Not sure what is construct to use for dynamiccast in C#.

    Thanks
  • xdm
    xdm La Coruña, Spain
    In C# you just use a normal cast
    Ice.ObjectPrx proxy = communicator.propertyToProxy("XYZ.Proxy");
    Ice.Endpoint[] seq = proxy.ice_getEndpoints();
    if(seq.Length > 0)
    {
         Ice.EndpointInfo info = seq[0].getInfo();
         Ice.IPEndpointInfo ipInfo = (Ice.IPEndpointInfo)info;
         WriteLine("host = " + ipInfo.host + ", port = " + ipInfo.port.ToString());
    }