-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMyClient.h
executable file
·123 lines (105 loc) · 3.82 KB
/
MyClient.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* License plate detection
* See COPYRIGHT file at the top of the source tree.
*
* This product includes software developed by the
* STARGUE Project (http://www.stargue.org/).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the STARGUE License Statement and
* the GNU General Public License along with this program. If not,
* see <http://www.lsstcorp.org/LegalNotices/>.
*/
/**
* @file MyClient.h
*
* @brief A client to send a request to a server
*
* @author Adama Zouma
*
* @Contact: stargue49@gmail.com
*
*/
#ifndef MY_CLIENT_H
#define MY_CLIENT_H
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <iostream>
//#include "Clock.h"
#include <Manager.h>
#include <tuple>
#include <time.h>
namespace za{
/**
* Implementation of a client
* This client uses a TCP/IP communication model
* to connect to a server
* Once connected the client sends the current
* time information to the server
* the client also wait for the server response
*/
class MyClient
{
private:
/* ============================================================================
* Data Memeber Declaration
* ============================================================================
*/
int socketConnectToClient_;
unsigned short serverPortNumber_;
int numberOfByteOfBuffer_;
//Clock clock;
struct sockaddr_in serverAddress_;
struct hostent *serverIP_;
za::Manager logManager;
za::my_logger::logger_type log = za::my_logger::get();
char buffer[1024];
public:
/* ============================================================================
* Member Function Declaration
* ============================================================================
*/
MyClient(char *_serverIP_, unsigned short _serverPort_);
int createClientForConnexion();
int connectClientToServer();
int sendRequestToServer();
int receiveResponseFromServer();
int closeConnexion();
int setLog(std::string& _logName_);
int setLog(std::string&& _logName_);
std::tuple <std::string, std::string> getCurrentTime();
// Setter and Getter socketConnectToClient
auto socketConnectToClient() const& -> const int& { return socketConnectToClient_; }
auto socketConnectToClient() & -> int& { return socketConnectToClient_; }
auto socketConnectToClient() && -> int&& { return std::move(socketConnectToClient_); }
// Setter and Getter serverPortNumber
auto serverPortNumber() const& -> const unsigned short& { return serverPortNumber_; }
auto serverPortNumber() & -> unsigned short& { return serverPortNumber_; }
auto serverPortNumber() && -> unsigned short&& { return std::move(serverPortNumber_); }
// Setter and Getter numberOfByteOfBuffer
auto numberOfByteOfBuffer() const& -> const int& { return numberOfByteOfBuffer_; }
auto numberOfByteOfBuffer() & -> int& { return numberOfByteOfBuffer_; }
auto numberOfByteOfBuffer() && -> int&& { return std::move(numberOfByteOfBuffer_); }
// Setter and Getter socketConnectToClient
auto serverAddress() const& -> const sockaddr_in& { return serverAddress_; }
auto serverAddress() & -> sockaddr_in& { return serverAddress_; }
auto serverAddress() && -> sockaddr_in&& { return std::move(serverAddress_); }
// Setter and Getter socketConnectToClient
};
}
#endif /* MY_CLIENT_H */