-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPPAsyncClientTest.cpp
More file actions
58 lines (49 loc) · 1.08 KB
/
Copy pathCPPAsyncClientTest.cpp
File metadata and controls
58 lines (49 loc) · 1.08 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
48
49
50
51
52
53
54
55
56
57
58
#include "ClientCode.h"
#include <Windows.h>
std::mutex m;
std::queue<boost::array<unsigned char, 1>> bufferQueue;
void Execute(boost::asio::io_context* io)
{
io->run();
}
int main()
{
boost::signals2::signal<void()> recvSignal;
recvSignal.connect([&] {
std::lock_guard<std::mutex> lg(m);
boost::array<unsigned char, 1> msg = bufferQueue.front();
std::string data(bufferQueue.front().begin(), bufferQueue.front().end());
std::cout << data;
bufferQueue.pop();
});
int option;
std::cout << "press 1 for server or 2 for client.\n";
std::cin >> option;
try
{
boost::asio::io_context io;
ClientCode client(&recvSignal, io, &m, &bufferQueue);
std::thread t(Execute, &io);
t.detach();
if (option == 1) {
system("pause");
t.~thread();
}
else {
//send unlimited packets!!!
int x = 0;
/*while(true)
{*/
Sleep(1);
x++;
std::cout << "sent[" << x << "]\n" ;
client.StartSend();
/*}*/
t.~thread();
}
}
catch (std::exception& e)
{
std::cerr << e.what() << std::endl;
}
}