-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.cpp
More file actions
57 lines (36 loc) · 736 Bytes
/
client.cpp
File metadata and controls
57 lines (36 loc) · 736 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
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
#include <iostream>
#include <thread>
#include "sockets.h"
static bool t_flag_stop = false;
void thread_recv(Sockets& app)
{
std::string buffer;
buffer.reserve(128);
do
{
if (app.read(buffer) != -1){
std::cout << "Server: " << buffer << "\n"; }
std::this_thread::yield();
} while (t_flag_stop != true);
return;
}
void thread_send(Sockets& app)
{
std::string buffer;
do {
std::getline(std::cin, buffer);
app.write(buffer);
std::this_thread::yield();
} while (buffer != "exit");
return;
}
int main()
{
Sockets client(7777);
std::thread t_recv(thread_recv, std::ref(client));
std::thread t_send(thread_send, std::ref(client));
t_send.join();
t_flag_stop = true;
t_recv.join();
return 0;
}