-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.cpp
More file actions
47 lines (35 loc) · 1.03 KB
/
client.cpp
File metadata and controls
47 lines (35 loc) · 1.03 KB
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
#include <iostream>
#include "sock_wrap.hpp"
#define ADDRESS "my_socket"
int main ()
{
// creating socket
UnClientSocket sock(ADDRESS);
signals_set_handlers();
try {
// connecting
sock.connect();
// writing messages
while (true) {
std::cout << "Enter your request:" << std::endl;
std::string input_line;
getline(std::cin, input_line, '\n');
if (std::cin.eof()) break;
int send_request = 1;
sock.write(&send_request, sizeof send_request);
sock.put_string(input_line);
size_t num_strings;
sock.read(&num_strings, sizeof num_strings);
std::cout << "Answer got:" << std::endl;
for (size_t i = 0; i < num_strings; ++i) {
std::cout << sock.get_string();
}
}
sock.shutdown();
sock.close();
} catch (const ExceptionBase &err) {
sock.close();
std::cerr << err << std::endl;
}
return 0;
}