Home Help Center

Query hostname based on connection information

vishreddykvishreddyk Member Vishwanath KasarlaOrganization: BarclaysProject: Risk System
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

  • benoitbenoit Rennes, FranceAdministrators, ZeroC Staff Benoit FoucherOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    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.
  • vishreddykvishreddyk Member Vishwanath KasarlaOrganization: BarclaysProject: Risk System
    What would be the C# version? Not sure what is construct to use for dynamiccast in C#.

    Thanks
  • xdmxdm La Coruña, SpainAdministrators, ZeroC Staff Jose Gutierrez de la ConchaOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    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());
    }
    
Sign In or Register to comment.