ACE_Asynch_Acceptor无法得到对方IP
创建一个类: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,该如何做呢?
谢谢啦 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().
页:
[1]