-
Notifications
You must be signed in to change notification settings - Fork 0
/
Server.h
86 lines (62 loc) · 1.57 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* Server.h
*
* Author: 314970054 Ariel Barmats &
* 314985474 Amiram Yasif
*/
#pragma once
#include <iostream>
#include <sys/socket.h> // The header file socket.h includes a number of definitions of structures needed for sockets.
#include <netinet/in.h> // The header file in.h contains constants and structures needed for internet domain addresses.
#include <pthread.h>
#include <thread>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <sstream>
#include "CLI.h"
using namespace std;
// edit your ClientHandler interface here:
class ClientHandler{
public:
virtual void handle(int clientID)=0;
};
// you can add helper classes
class socketIO:public DefaultIO{
int clientID;
public:
socketIO(int clientID):clientID(clientID){}
virtual string read();
virtual void write(string text);
virtual void write(float f);
virtual void read(float* f);
};
// edit your AnomalyDetectionHandler class here
class AnomalyDetectionHandler:public ClientHandler{
public:
virtual void handle(int clientID){
socketIO sio(clientID);
CLI cli(&sio);
cli.start();
}
};
/**
* implement on Server.cpp
* Server shuts down in 2 seconds.
*/
class Server {
// you may add data members
int fd;
sockaddr_in server;
sockaddr_in client;
pid_t server_pid;
thread* serverListenerThread;
volatile bool isRunning;
public:
Server(int port) throw (const char*);
virtual ~Server();
pid_t start(ClientHandler& ch)throw(const char*);
void stop();
};