|
t.remote_address (peerAddr);
ACE_DEBUG ((LM_DEBUG, "%s = %s:%d\n", "peer_address", peerAddr.get_host_addr (), peerAddr.get_port_number ()));
ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "flags", result.flags ()));
ACE_DEBUG ((LM_DEBUG, "%s = %s\n", "act", result.act ()));
ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "success", result.success ()));
ACE_DEBUG ((LM_DEBUG, "%s = %s\n", "completion_key", result.completion_key ()));
ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "error", result.error ()));
ACE_DEBUG ((LM_DEBUG, "********************\n"));
if (result.success () && result.bytes_transferred () != 0)
{
// loop through our message block and print out the contents
for (const ACE_Message_Block* msg = result.message_block (); msg != 0; msg = msg->cont ())
{ // use msg->length () to get the number of bytes written to the message
// block.
ACE_DEBUG ((LM_DEBUG, "Buf=[size=<%d>", msg->length ()));
for (u_long i = 0; i < msg->length (); ++i)
ACE_DEBUG ((LM_DEBUG,
"%c", (msg->rd_ptr ())[i]));
ACE_DEBUG ((LM_DEBUG, "]\n"));
}
}
ACE_DEBUG ((LM_DEBUG,
"Receiver completed\n"));
// No need for this message block anymore.
result.message_block ()->release ();
// Note that we are done with the test.
done++;
}
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
//ACE_LOG_MSG->set_flags(ACE_Log_Msg::STDERR | ACE_Log_Msg::VERBOSE);
Receiver receiver;
if (receiver.open_addr (ACE_INET_Addr (port)) == -1)
return -1;
while (true)
{
ACE_Proactor::instance ()->handle_events ();
}
return 0;
}
先运行接收端,再运行发送端,你懂的。
发送端程序运行结果:

接收端运行结果:

定时多目标发送
程序的功能:
(1)UDP发送内容到P1,IP2,...,IPn(地址列表从文件读取) (1)发送内容从文件中读取; (1)发送时间间隔从文件中读取;
//=============================================================================
/**
* @file test_udp_proactor.cpp
*
* $Id: test_udp_proactor.cpp 93639 2011-03-24 13:32:13Z johnnyw $
*
* This program illustrates how the
can be used to
* implement an application that does asynchronous operations using
* datagrams.
*
*
* @author Irfan Pyarali
and Roger Tragin
*/ //============================================================================= #include
#include
#include
#include
#include
using namespace std; //#include "ace/Reactor.h" #include "ace/Message_Queue.h" #include "ace/Asynch_IO.h" #include "ace/OS.h" #include "ace/Proactor.h" #include "ace/Asynch_Connector.h" #include
#include "ace/OS_NS_string.h" #include "ace/OS_main.h" #include "ace/INET_Addr.h" #include "ace/SOCK_Dgram.h" #include "ace/Message_Block.h" #include "ace/Get_Opt.h" #include "ace/Log_Msg.h" #include "ace/Event_Handler.h" #include "ace/Date_Time.h" #include "ace/WIN32_Proactor.h" namespace global { int delay = 2; //int interval = 60*10;//每interval 秒计时一次 int interval = 2;//每interval 秒计时一次 void print_current_time(void) { ACE_Date_Time date(ACE_OS::gettimeofday()); cout<<"当前时间:" <
bool read_server_addr(vector
& addrs) { ifstream fin("server_addr.ini"); if (!fin) { cout<<"找不到配置文件:local_port.ini"<
first(fin),last; vector
temp_addrs(first,last); if (temp_addrs.size()==0) { cout<<"配置文件中找不到服务器地址!"<
bool read_interval(T& interval) { ifstream fin("interval_second.ini"); if (!fin) { cout<<"找不到配置文件:interval_second.ini"<
first(fin),last; //vector
temp_addrs(first,last); fin>>interval; if (!fin) { cout<<"配置文件中找不到发送时间间隔数据!"<
. */ class Sender : public ACE_Handler, public ACE_Event_Handler { public: Sender (const int delay,const int interval); ~Sender (void); //FUZZ: disable check_for_lack_ACE_OS ///FUZZ: enable check_fo |