Beispiel #1
0
int main(int argc , const char *argv[])
{
	if (argc != 3)
	{
		Usage(argv[0]);
		exit(1);
	}

	std::string ip = argv[1];
	short int port = atoi(argv[2]);
	udp_server _ser(ip, port);
    pthread_t tid1;
	pthread_t tid2;
	pthread_create(&tid1, NULL, recv, (void*)&_ser);
	pthread_create(&tid2, NULL, broad_cast, (void*)&_ser);
    
	pthread_join(tid1, NULL);
	pthread_join(tid2, NULL);

//	std::string out;
//	while (1)
//	{
//		_ser.recv_data(out);
//		std::cout<<"client# "<<out<<std::endl;
//	}
	return 0;
}
Beispiel #2
0
int main(int argc,char* argv[])
{
	if(argc != 3){
		usage(argv[0]);
		return 1;
	}
	
	daemon(0,0);

	short _port = atoi(argv[2]);
	string _ip = argv[1];
	udp_server _ser(_ip,_port,20);
	_ser.init_server();
	

	pthread_t recv_thread;
	pthread_t broadcast_thread;
	pthread_create(&recv_thread,NULL,recv_handler,(void*)&_ser);
	pthread_create(&broadcast_thread,NULL,broadcast_handler,(void*)&_ser);

	pthread_join(recv_thread,NULL);
	pthread_join(broadcast_thread,NULL);

//	string _out;
//	bool done = true;
//	while(done){
//		_ser.recv_data(_out);
//		cout<<_out<<endl;
//	}

//	cout<<"hello world"<<endl;
}