1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
#include <iostream>
#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <string.h>
#include <string>
#include <stdlib.h>
#include <ctime>
#include <fstream>
using namespace std;
void hblisten (int clientSocket){
char buf[4096];
memset(buf, 0, 4096);
int clienthblisten = recv(clientSocket, buf, 4096, 0);
int numofclients = 0;
string lines;
ifstream CLIENTK;
CLIENTK.open(".ckeylist");
while (getline(CLIENTK, lines))
++numofclients;
CLIENTK.close();
struct clientservers{
string CLIENT, CKEY;
bool clientok = false;
}clients[numofclients];
ifstream CLIENTK1(".ckeylist", ios::in);
CLIENTK1.open(".ckeylist");
for (int i=0; i < numofclients; i++) {
getline(CLIENTK1, clients[i].CLIENT, ':');
getline(CLIENTK1, clients[i].CKEY, '\n');
++numofclients;
}
CLIENTK1.close();
string clientkey = string(buf, 0, clienthblisten);
if (clienthblisten == -1) {
cerr << "Error receiving client HB" << endl;
exit(1);
}
if (clienthblisten == 0) {
cout << "Client disconnected" << endl;
}
if (clienthblisten >1){
if(strcmp(clientkey.c_str(), clients[numofclients].CKEY.c_str()) ==0){
clients[numofclients].clientok == true;
}
}
if(clients[numofclients].clientok == true){
do something();
}
|