Archived

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

how to know which port the adapter is using?

if i create a adapter using below statement:

Ice::ObjectAdapterPtr adapter= ic->createObjectAdapterWithEndpoints("sp", "tcp");

because the port is not specified, it will be selected by the operating system.

but now i want to know which port the opeating system selected for the adapter?

thanks for your reply.

Comments

  • benoit
    benoit Rennes, France
    Hi,

    There's no way to get this information directly. You can however create a proxy with the adapter and get the port number from the stringified proxy, for example:
       // C++
       Ice::ObjectAdapterPtr adapter  = communicator->createObjectAdapterWithEndpoints("MyAdapter", "tcp");
       cout << adapter->createProxy(communicator->stringToIdentity("Dummy"))->ice_toString() << endl;
    

    You can also enable network tracing with --Ice.Trace.Network=1 to see on which port the object adapter is listening.

    Cheers,
    Benoit.
  • Is this still the most current information for this particular problem?

    We have a situation where we require running more than one server on a machine, each running as different users. So a statically defined port won't work for us. Being able to figure out what port was selected automatically without having to do some crazy regex on a string would be greatly beneficial.
  • matthew
    matthew NL, Canada
    Sorry, other than the technique recommended by Benoit (parsing strings), there is no way to retrieve this information.

    An alternative to parsing the stringified form of the proxy is to call ice_getEndpoints() on the proxy, which returns a sequence of Endpoints. Then on each endpoint call toString() which, for a tcp endpoints, would return something like "tcp -h ... -p ...". This might be marginally easier to parse.

    Out of curiosity, why do you need this information?
  • Basically, we have an application that spawns child processes, and we want the child to be able to communicate with the parent process bi-directionally via Ice. To initiate the communication the child needs to know what port to connect to on the parent. The parent port isn't known ahead of time because there could be N copies of it running on a particular host, any of them as a different user. So the parent needs to pass the port as a parameter to the child.
  • mes
    mes California
    Hi Kris,

    Instead of passing only the port to the child process, have you considered passing a stringified proxy?

    Regards,
    Mark
  • No I haven't. Now that I think of it, I think that would completely solve my problem. I'm so used to thinking in terms of hosts and ports I never even considered just passing around a stringified proxy.

    Thanks for the tip!
  • mes
    mes California
    There are a couple of things you should keep in mind if you decide to pass a stringified proxy to a child process. First of all, the string will contain spaces, so you may need to enclose it in quotes depending on how you are spawning the child. Second, the stringified proxy itself may contain quotes if the proxy's identity name or category has spaces. Of course, you only need to worry about the second issue if it's possible for your identities to contain spaces.

    Take care,
    Mark
  • meaning of '-t' flag in stringfied endpoint??

    Hi,

    When creating a server proxy (which acts as a server),
    IceAdapter = IceCommunicator->createObjectAdapterWithEndpoints(AdapterName, EndpointInfo);
    std::string s = IceAdapter->createProxy(IceCommunicator->stringToIdentity("Dummy"))->ice_toString();
    This code snippet sets string s as "Dummy -t:tcp -h xx.xx.xx.xx -p 1234 -t 3000".
    I wonder what's the meaning of "-t" flag right in front of "tcp" keyword.

    Thanks for your answer in advance,
    Min
  • dwayne
    dwayne St. John's, Newfoundland
    The '-t' means that the proxy is configured for twoway operations. See here for documentation on proxy options.