当前位置: 首页>>代码示例>>C++>>正文


C++ Targets::end方法代码示例

本文整理汇总了C++中Targets::end方法的典型用法代码示例。如果您正苦于以下问题:C++ Targets::end方法的具体用法?C++ Targets::end怎么用?C++ Targets::end使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Targets的用法示例。


在下文中一共展示了Targets::end方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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;
}
开发者ID:boris-r-v,项目名称:STD,代码行数:70,代码来源:udp2udp.cpp


注:本文中的Targets::end方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。