zero ice 如何获取本地以及对端IP 地址及端口号

时间:2022-02-09 00:03:56
 // 在客户端显示端点连接IP及端口号信息
static void show_endpoint(const Ice::ObjectPrx &proxy)
{
Ice::ConnectionPtr conn = proxy->ice_getConnection();
if(conn)
{
cout << conn->type() << endl;
cout << conn->toString() << endl;
Ice::ConnectionInfoPtr conn_info = conn->getInfo();
::Ice::EndpointPtr ep_ptr = conn->getEndpoint();
cout << ep_ptr->toString() << endl; Ice::IPConnectionInfoPtr ipInfo = Ice::IPConnectionInfoPtr::dynamicCast(conn_info);
cout << ipInfo->localAddress << ":" << ipInfo->localPort << endl;
cout << ipInfo->remoteAddress << ":" << ipInfo->remotePort << endl;
}
else
{
cout << "collocated" << endl;
}
}