本文整理汇总了C++中Targets::push_back方法的典型用法代码示例。如果您正苦于以下问题:C++ Targets::push_back方法的具体用法?C++ Targets::push_back怎么用?C++ Targets::push_back使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Targets
的用法示例。
在下文中一共展示了Targets::push_back方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getTargets
brion::Targets BlueConfig::getTargets() const
{
Targets targets;
const URIs& uris = getTargetSources();
for (const URI& uri : uris)
targets.push_back(Target(uri.getPath()));
return targets;
}
示例2: main
int main( int argc, char** argv ){
// ipxComm* ipx = new ipxComm( ipxPort ,false);
if(argc<3){
std::cerr<<" no one targets !"<<std::endl;
return 1;
}
int inUdpPort=14310;
char * ip = cip;
inUdpPort = atoi(argv[1]);
std::cout<<" udp to udp translator. udp port listen "<<inUdpPort<<std::endl;
//sockaddr_in sa_out;
//sa_out.sin_family = AF_INET;
//sa_out.sin_addr.s_addr = inet_addr( ip );
//sa_out.sin_port = htons( outUdpPort);
int size = argc-2;
Targets targets;
std::string ipStr;
int ipPort=0;
for( int i = 2 ; i < argc ;i++ ){
parseIp( std::string(argv[i]),ipStr,ipPort );
sockaddr_in sa_out;
sa_out.sin_family = AF_INET;
sa_out.sin_addr.s_addr = inet_addr( ipStr.c_str() );
sa_out.sin_port = htons( ipPort );
targets.push_back(sa_out);
std::cout<<"target "<<ipStr<<":"<<ipPort<<" added "<<std::endl;
}
int sockOut = socket( PF_INET, SOCK_DGRAM , 0 );
int sockIn = socket( PF_INET, SOCK_DGRAM , 0 );
int flag = 1;
sockaddr_in sa_in;
sa_in.sin_family = AF_INET;
sa_in.sin_addr.s_addr = INADDR_ANY;
sa_in.sin_port = htons( inUdpPort );
if(!bind(sockIn,(sockaddr*)&sa_in,sizeof(sa_in))){
std::cout<<" socket binded on port "<<inUdpPort<<std::endl;
}
unsigned char* pack = new unsigned char[packSize];
unsigned char* udpPack = new unsigned char[packSize];
Net::InfoPackHeader* iph = (Net::InfoPackHeader*)udpPack;
if(!setsockopt(sockOut,SOL_SOCKET,SO_BROADCAST,&flag,sizeof(flag))){
std::cout<<"Start work "<<std::endl;
Targets::iterator start = targets.begin();
Targets::iterator end = targets.end();
while(1){
if( unsigned recsize = recv(sockIn,pack,packSize,0)){
while( start != end ){
if( sendto(sockOut,pack,recsize,MSG_NOSIGNAL,(sockaddr*)(&(*start)),sizeof(sockaddr_in)) <0 ){
std::cout<<"can`t send to "<<(*start).sin_port<<std::endl;
}else{
std::cout<<"packsize "<<recsize<<" send to "<<inet_ntoa((*start).sin_addr)<<":"<<ntohs( (*start).sin_port )<<std::endl;
}
++start;
}
start = targets.begin();
std::cout<<std::endl;
}
}
}
return 0;
}