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


C++ Sock::good方法代码示例

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


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

示例1: main

int main(int args,char* argv[]) {
	int port, desCurrentClient, DesServer, localBR, nb_connected_client(0);
	struct sockaddr_in brCv;
	socklen_t sizeLocalBr;
	
	int nb_client = 5;
  client_t listeClientsEntreprise[nb_client];
	
// On définit un pointeur sur la structure data
  data_t data = (data_t)malloc(sizeof(data_t));
  data->ptr_client_list = listeClientsEntreprise;
  data->nb_connected_client= &nb_connected_client;

// Test création client
	client_t testcli = (client_t) malloc(sizeof(Client));
	sprintf(testcli->name,"tintin");	
	sprintf(testcli->password,"milou");
	testcli->claimed_report=false;
	testcli->received_report=0;
	testcli->controller=false;
	
	client_t testcli2 = (client_t) malloc(sizeof(Client));
	sprintf(testcli2->name,"bob");	
	sprintf(testcli2->password,"boby");
	testcli2->claimed_report=true;
	testcli2->received_report=0;
	testcli2->controller=false;
	
	client_t testcli3 = (client_t) malloc(sizeof(Client));
	sprintf(testcli3->name,"tutu");	
	sprintf(testcli3->password,"boby");
	testcli3->claimed_report=true;
	testcli3->received_report=1;
	testcli3->controller=false;
	
	client_t testcli4 = (client_t) malloc(sizeof(Client));
	sprintf(testcli4->name,"beber");	
	sprintf(testcli4->password,"boby");
	testcli4->claimed_report=false;
	testcli4->received_report=2;
	testcli4->controller=false;
	
	client_t testController = (client_t) malloc(sizeof(Client));
	sprintf(testController->name,"haddock"); // enfin lui !
	sprintf(testController->password,"boby");
  testController->controller=true;
  testController->received_report=0;
  
	listeClientsEntreprise[0] = testcli;
	listeClientsEntreprise[1] = testcli2;
	listeClientsEntreprise[2] = testcli3;
	listeClientsEntreprise[3] = testcli4;
	listeClientsEntreprise[4] = testController;
	data->nb_client = &nb_client;


	if(args == 2) {
		cout << "N° port saisi : "<< argv[1] << endl;
		port = atoi(argv[1]);
	}
	else {
		cout << "Numéro du port du server : ";	
		cin >> port;
	}
	
	/* Création de la BR Publique */
	Sock* server = new Sock(SOCK_STREAM,(short)htons(port),0);
	if(server->good()) {
		cout << "Server lancé !" << endl;		
		DesServer = server->getsDesc();
		localBR = server-> getsRetour();
		sizeLocalBr = sizeof(brCv);
	}
	else {
		perror("Erreur employee->des_client()");
		exit(EXIT_FAILURE);
	}
	
	if(listen(DesServer,10) == -1)
	perror("Erreur listen()");

	while(1)
	{
/* Acceptation de la connexion du Client */
		desCurrentClient = accept(DesServer,(struct sockaddr *)&brCv,&sizeLocalBr);
		if(desCurrentClient == -1)
			perror("Erreur accept ");
		else 
		{
  		pthread_t idThread; 
			cout<< endl <<endl << " <=== Nouveau Client accepté ===>" << endl;
		  data->descripteur = desCurrentClient;
			
			if(pthread_create(&idThread,NULL,th_new_client,(void*)data) != 0) {
        perror("Erreur création th_new_client");
      }
		}// End if Client accepté
	} // End loop
	
	 pthread_mutex_destroy(&mutex);
//.........这里部分代码省略.........
开发者ID:Bob-Bernard,项目名称:Projet_Reseau,代码行数:101,代码来源:serverounet.cpp


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