Archived

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

FAQ contains incorrect code?

I looked at the FAQ: "How can a server get the IP address of the caller"

I'm using the latest 3.4. Here is what it lists:

> Ice::ConnectionInfo info = c.con->getInfo();

getInfo() does not return Ice::ConnectionInfo ?

> Ice::TCPConnectionInfo tcpInfo =
> Ice::TCPConnectionInfo::dynamicCast(c.con);

There is no TCPConnectionInfo and no dynamicCast?

if(ipInfo)
{
...

Where is ipInfo defined?

Please explain what I'm missing.

Thanks,

-Oliver

Comments

  • mes
    mes California
    Hi Oliver,

    Welcome to the forum!

    There are a few bugs in that example code, thanks for bringing this to our attention. I've fixed the FAQ, and here's what the code should have been:
        if(c.con)
        {
            Ice::ConnectionInfoPtr info = c.con->getInfo();
            Ice::TCPConnectionInfoPtr tcpInfo =
                Ice::TCPConnectionInfoPtr::dynamicCast(info);
            if(tcpInfo)
            {
                cout << "local address = " << tcpInfo->localAddress << ":"
                     << tcpInfo->localPort << endl;
                cout << "remote address = " << tcpInfo->remoteAddress << ":"
                     << tcpInfo->remotePort << endl;
            }
        }
    
    I've verified that this compiles. :)

    Let us know if you still have questions.

    Regards,
    Mark