Results 1 to 10 of 10

Thread: how to know which port the adapter is using?

  1. #1
    nyingchi is offline Registered User
    Join Date
    Aug 2006
    Posts
    13

    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.
    kin Young

    university: Sun Yat-sen University

    url: http://www.sysu.edu.cn
    learning ICE.

  2. #2
    benoit's Avatar
    benoit is offline ZeroC Staff
    Name: Benoit Foucher
    Organization: ZeroC, Inc.
    Project: Ice
    Join Date
    Feb 2003
    Location
    Rennes, France
    Posts
    2,196
    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:

    Code:
       // 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.

  3. #3
    kundertk is offline Registered User
    Name: Kris Kundert
    Organization: Enbridge Pipelines Inc.
    Project: IPC replacement
    Join Date
    Jun 2008
    Posts
    3
    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.
    Last edited by kundertk; 07-04-2008 at 10:48 AM. Reason: Adding more context..

  4. #4
    matthew's Avatar
    matthew is offline ZeroC Staff
    Name: Matthew Newhook
    Organization: ZeroC, Inc.
    Project: Internet Communications Engine
    Join Date
    Feb 2003
    Location
    NL, Canada
    Posts
    1,458
    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?

  5. #5
    kundertk is offline Registered User
    Name: Kris Kundert
    Organization: Enbridge Pipelines Inc.
    Project: IPC replacement
    Join Date
    Jun 2008
    Posts
    3
    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.

  6. #6
    mes's Avatar
    mes
    mes is online now ZeroC Staff
    Name: Mark Spruiell
    Organization: ZeroC, Inc.
    Project: Ice Developer
    Join Date
    Feb 2003
    Location
    California
    Posts
    1,441
    Hi Kris,

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

    Regards,
    Mark

  7. #7
    kundertk is offline Registered User
    Name: Kris Kundert
    Organization: Enbridge Pipelines Inc.
    Project: IPC replacement
    Join Date
    Jun 2008
    Posts
    3
    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!

  8. #8
    mes's Avatar
    mes
    mes is online now ZeroC Staff
    Name: Mark Spruiell
    Organization: ZeroC, Inc.
    Project: Ice Developer
    Join Date
    Feb 2003
    Location
    California
    Posts
    1,441
    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

  9. #9
    smmy is offline Registered User
    Name: Min Yang Jung
    Organization: Johns Hopkins University
    Project: CISST/SAW
    Join Date
    Jan 2010
    Posts
    2

    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

  10. #10
    dwayne's Avatar
    dwayne is offline ZeroC Staff
    Name: Dwayne Boone
    Organization: ZeroC, Inc.
    Project: Internet Communications Engine
    Join Date
    Jan 2005
    Location
    St. John's, Newfoundland
    Posts
    397
    The '-t' means that the proxy is configured for twoway operations. See here for documentation on proxy options.
    Dwayne Boone

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Port forwarding
    By devtty in forum Help Center
    Replies: 9
    Last Post: 10-19-2009, 01:22 PM
  2. C Port
    By slide_o_mix in forum Help Center
    Replies: 1
    Last Post: 01-27-2008, 08:12 PM
  3. QNX port
    By n2503v in forum Help Center
    Replies: 5
    Last Post: 12-18-2006, 05:16 PM
  4. how to bind 0.0.0.0:port ?
    By ewiniar in forum Help Center
    Replies: 3
    Last Post: 06-22-2006, 09:15 PM
  5. AIX Port
    By ScottDiedrick in forum Help Center
    Replies: 1
    Last Post: 04-13-2004, 04:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •