|
楼主 |
发表于 2009-10-16 09:07:07
|
显示全部楼层
回复 #2 modern 的帖子
但我如何调用address函数,还是系统调用的。还是不明白如何获得客户端的地址
服务器端代码:
HA_Proactive_Service类
virtual void address
(const ACE_INET_Addr &remote_address, const ACE_INET_Addr &local_address)
{
CPserverDlg *dlg=(CPserverDlg*)AfxGetApp()->GetMainWnd();
CString str;
str.Format("地址:%d",remote_address.get_ip_address());
dlg->MessageBox(str);
// cout << remote_address.get_ip_address() << endl;
}
virtual void open (ACE_HANDLE h, ACE_Message_Block&)
{
// _cur[num] = this;
// num++;
_cur=this;
List.push_back(_cur);
this->handle (h) ;
if (this->writer_.open (*this) != 0 ||this->reader_.open(*this) !=0)
{
ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"),
ACE_TEXT ("HA_Proactive_Service open")));
delete this;
return;
}
ACE_Message_Block *mb;
ACE_NEW_NORETURN(mb,ACE_Message_Block(8102));
if (this->reader_.read(*mb, mb->space ()) != 0)
{
ACE_OS::printf("Begin read fail\n");
delete this;
mb->release();
return;
}
return;
}
对话框.cpp
UINT ThreadReactor(LPVOID param)
{
ACE_INET_Addr listen_addr(3000);
ACE_Asynch_Acceptor<HA_Proactive_Service>aio_acceptor;
if (0 != aio_acceptor.open(listen_addr, 0, 0, 5, 1, 0, 0))
ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("acceptor open")), 1);
CPserverDlg *dlg=(CPserverDlg*)AfxGetApp()->GetMainWnd();
dlg->MessageBox("服务器已启动");
int result = ACE_Proactor::instance ()->proactor_run_event_loop ();
ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Thread ended\n")));
return result;
}
void CPserverDlg::OnStart()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
AfxBeginThread(ThreadReactor,NULL);
UpdateData(FALSE);
}
void CPserverDlg::OnStop()
{
// TODO: Add your control notification handler code here
ACE_Proactor::instance()->proactor_end_event_loop();
} |
|