先运行接收端,再运行发送端,你懂的。
发送端程序运行结果:

接收端运行结果:

定时多目标发送
程序的功能:
(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 thecan 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