本文整理汇总了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);
//.........这里部分代码省略.........