-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_Client.cpp
49 lines (40 loc) · 969 Bytes
/
client_Client.cpp
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
#include "client_Client.h"
#include "common_Guesser.h"
#include "common_Resources.h"
#include "common_Socket.h"
#include <iostream>
#include <fstream>
Client::Client(char* host, char* port) {
this->skt.connect(host, port);
}
Client::~Client() {
this->skt.close();
}
void Client::run() {
std::string input;
std::string response;
while (std::getline(std::cin, input)) {
try {
if (g.validClientInput(input)) {
this->send(input);
response = this->receive();
std::cout << response << "\n";
if (response==WIN_MSG or response==LOSE_MSG) break;
}
} catch (SocketError &e) {
continue;
} catch (std::exception &e) {
std::cerr << e.what() << std::endl;
break;
} catch (...) {
std::cerr << "Unknown Error on Client Run" << std::endl;
break;
}
}
}
void Client::send(std::string &msg) {
p.send(this->skt, msg);
}
std::string Client::receive() {
return p.receive(this->skt,'T');
}