-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
55 lines (49 loc) · 1.28 KB
/
test.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
47
48
49
50
51
52
53
54
55
#include <thread>
#include <iostream>
#include "sslxx.h"
const std::string text = "Hello, server :)";
class client : public sslxx::connector {
public:
client(const char *addr, int port) : sslxx::connector(addr, port) {}
void start() {
while (true) {
if (auto stream = connect()) {
stream->send(text);
break;
}
std::this_thread::yield();
}
}
};
class server : public sslxx::listener {
public:
server(int port) : sslxx::listener(port, "server.pem") {}
void start() {
while (true) {
if (auto stream = accept()) {
std::cout << (stream->receive() == text ? "OK" : "FAIL") << '\n';
break;
}
}
}
};
int main(int argc, char *argv[])
{
try {
std::thread worker([]() {
try {
client("127.0.0.1", 8080).start();
} catch(const std::exception &e) {
std::cout << "client exception: " << e.what() << '\n';
exit(1);
}
});
server server(8080);
server.start();
worker.join();
} catch(const std::exception &e) {
std::cout << "server exception: " << e.what() << '\n';
exit(1);
}
return 0;
}