找回密码
 用户注册

QQ登录

只需一步,快速开始

查看: 4175|回复: 1

ACE_Asynch_Acceptor无法得到对方IP

[复制链接]
发表于 2008-7-13 22:47:46 | 显示全部楼层 |阅读模式
创建一个类:Test_Acceptor : public ACE_Asynch_Acceptor<Receiver>
当有连接到来时调用的validate_connection代码如下:
int Test_Acceptor :: validate_connection(const ACE_Asynch_Accept::Result& result,
                                                                        const ACE_INET_Addr& remote,
                                                                        const ACE_INET_Addr& local)
{
             ACE_INET_Addr remote_Addr_ = remote;
             ACE_INET_Addr local_Addr_ = local;
     memset(peer_name,0,sizeof(peer_name));
     cout<<"peer_name:"<<peer_name<<endl;
     memset (local_ip, 0, sizeof(local_ip));
     remote_Addr_.addr_to_string(peer_name,20);
     cout<<"peer_name2:"<<peer_name<<endl;
     if(!remote.is_any())
     {
         cout<<"no ip!!!"<<endl;
     }
     local_Addr_.addr_to_string(local_ip, 20);
     ACE_DEBUG ((LM_INFO, "in Test_Acceptor::validate,Guest IP is :%s\n", peer_name));
     ACE_DEBUG ((LM_INFO, "in Test_Acceptor::validate,Local IP is :%s\n", local_ip));
     return 0;
}
程序运行时客户端可以与服务器端正常交互,但上面这段代码无法得到IP,Guest IP和Local IP输出都为空
不知道哪里出错了。如果要得到本机和客户端的IP,该如何做呢?
谢谢啦
 楼主| 发表于 2008-7-13 22:47:59 | 显示全部楼层
The pass_addresses argument is of some importance if your handler requires the local and peer addresses when running the service. The only portable way to obtain the local and peer addresses for asynchronously established connections is to implement the ACE_Service_Handler::addresses() hook method and pass a nonzero value as the pass_addresses argument to ACE_Asynch_Acceptor::open().
您需要登录后才可以回帖 登录 | 用户注册

本版积分规则

Archiver|手机版|小黑屋|ACE Developer ( 京ICP备06055248号 )

GMT+8, 2024-5-9 23:44 , Processed in 0.013852 second(s), 6 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表