Home Help Center

FAQ contains incorrect code?

oliverkoliverk Member Oliver KozberOrganization: SynopsysProject: Electronic Design Automation Tools
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

  • mesmes CaliforniaAdministrators, ZeroC Staff Mark SpruiellOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    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
Sign In or Register to comment.