-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.cpp
77 lines (63 loc) · 1.44 KB
/
client.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "clarcnet.h"
#include <cassert>
#include <iostream>
using namespace clarcnet;
int main(int argc, char* argv[]) {
client* cl = new client("localhost", 1111, clarcnet::ms(10000));
for (;;) {
auto ps = cl->process();
for (auto const& p : ps) {
switch (p.mid) {
case ID_CONNECTION:
{
std::cout << "connected" << std::endl;
packet p(0, ID_USER);
p.push_back('1');
p.push_back('2');
p.push_back('3');
p.push_back('4');
p.push_back('5');
p.push_back('6');
p.push_back('7');
cl->send(std::move(p));
packet p2(0, ID_USER);
p2.push_back('h');
p2.push_back('e');
p2.push_back('l');
p2.push_back('l');
p2.push_back('o');
auto sent = cl->send(std::move(p2));
assert(sent == p2.size());
// packet p3(0, ID_USER);
// for (auto i = 0; i < 100000; ++i)
// p3.push_back('a' + i % 26);
// cl->send(p3);
}
break;
case ID_DISCONNECTION:
{
std::cout << "disconnected" << std::endl;
return EXIT_FAILURE;
}
break;
case ID_TIMEOUT:
{
std::cout << "timed out" << std::endl;
return EXIT_FAILURE;
}
break;
case ID_USER:
{
std::cout << "server " << p.fd << " sent user data of size " << p.size() << std::endl;
for (auto i = 1; i < p.size(); ++i)
std::cout << p[i];
std::cout << std::endl;
}
break;
default:
break;
}
}
}
return EXIT_SUCCESS;
}