-
Notifications
You must be signed in to change notification settings - Fork 0
/
Server.h
66 lines (48 loc) · 1.2 KB
/
Server.h
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
63
64
65
66
//Orpaz Sondhelm 206492324 Yarin Tzdaka 319091278
#ifndef SERVER_H_
#define SERVER_H_
#include "commands.h"
#include "CLI.h"
#include <netinet/in.h>
#include <iostream>
#include <sys/socket.h>
#include <thread>
#include <unistd.h>
using namespace std;
class ClientHandler{
public:
virtual void handle(int clientID)=0;
};
// you can add helper classes here and implement on the cpp file
class socketIO:public DefaultIO{
int cltID;
public:
socketIO(int cltID):cltID(cltID){}
virtual string read();
virtual void read(float* f);
virtual void write(string text);
virtual void write(float f);
};
// edit your AnomalyDetectionHandler class here
class AnomalyDetectionHandler:public ClientHandler{
public:
virtual void handle(int clientID){
socketIO sock(clientID);
CLI cli(&sock);
cli.start();
}
};
// implement on Server.cpp
class Server {
thread* t; // the thread to run the start() method in
int sock;
sockaddr_in sockServer;
sockaddr_in sockClient;
bool stopFlag;
public:
Server(int port) throw (const char*);
virtual ~Server();
void start(ClientHandler& ch)throw(const char*);
void stop();
};
#endif /* SERVER_H_ */