-
Notifications
You must be signed in to change notification settings - Fork 0
/
TCPServer.h
44 lines (35 loc) · 1.22 KB
/
TCPServer.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
#ifndef IPK_TCPSERVER_H
#define IPK_TCPSERVER_H
#include "server.h"
class TCPServer: public Server {
public:
std::array<int, 30>expected;
TCPServer();
~TCPServer() override;
/// Set up the server
/// \param hostname DNS name or IPv4 address of the server
/// \param port Port number
void SetUpServer(const char *hostname, const uint16_t port) override;
/// Communicate with a client
void communicate() override;
private:
/// Create a TCP socket
void create_tcp_socket();
/// Get the response to be sent to the client
/// \param message The query
/// \param expected The expected query
/// \return The response
std::string get_tcp_response(std::string message, int* expected);
/// Get the query from the client
/// \param client Socket descriptor of the client
/// \param buf Buffer to store the query
/// \return The query
std::string get_tcp_query(const int* client, char* buf);
/// Send the response to the client
/// \param client Socket descriptor of the client
/// \param message The response
/// \param expected The status to be reset
/// \param socket The socket descriptor of the server
void send_tcp_message(const int *client, std::string message, int* expected, int* socket);
};
#endif //IPK_TCPSERVER_H