-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.cpp
More file actions
32 lines (25 loc) · 685 Bytes
/
Copy pathClient.cpp
File metadata and controls
32 lines (25 loc) · 685 Bytes
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
#include "Client.h"
#include <stdexcept>
#include <iostream>
#include <sstream>
#include <algorithm>
using namespace std;
Client::Client(string ip, const int port) {
if (!socket.create()) {
throw SocketException("Failed to create a socket");
} else if (!socket.connect(ip, port)) {
throw SocketException("Client couldn't connect to " + ip + ":" + to_string(port));
}
}
Client::~Client() {
cout << "Close client socket" << endl;
socket.close();
}
Client& Client::operator<<(const std::string &message) {
socket << message;
return *this;
}
Client& Client::operator>>(std::string &response) {
socket >> response;
return *this;
}