forked from button-chen/buttonrpc_cpp14
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_client.cpp
More file actions
executable file
·78 lines (62 loc) · 1.68 KB
/
Copy pathmain_client.cpp
File metadata and controls
executable file
·78 lines (62 loc) · 1.68 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <string>
#include <iostream>
#include <ctime>
#include "buttonrpc.hpp"
#ifdef _WIN32
#include <Windows.h> // use sleep
#else
#include <unistd.h>
#endif
#define buttont_assert(exp) { \
if (!(exp)) {\
std::cout << "ERROR: "; \
std::cout << "function: " << __FUNCTION__ << ", line: " << __LINE__ << std::endl; \
system("pause"); \
}\
}\
struct PersonInfo
{
int age;
std::string name;
float height;
// must implement
friend Serializer& operator >> (Serializer& in, PersonInfo& d) {
in >> d.age >> d.name >> d.height;
return in;
}
friend Serializer& operator << (Serializer& out, PersonInfo d) {
out << d.age << d.name << d.height;
return out;
}
};
int main()
{
buttonrpc client;
client.as_client("127.0.0.1", 5555);
client.set_timeout(2000);
int callcnt = 0;
while (1){
std::cout << "current call count: " << ++callcnt << std::endl;
client.call<void>("foo_1");
client.call<void>("foo_2", 10);
int foo3r = client.call<int>("foo_3", 10).val();
buttont_assert(foo3r == 100);
int foo4r = client.call<int>("foo_4", 10, "buttonrpc", 100, (float)10.8).val();
buttont_assert(foo4r == 1000);
PersonInfo dd = { 10, "buttonrpc", 170 };
dd = client.call<PersonInfo>("foo_5", dd, 120).val();
buttont_assert(dd.age == 20);
buttont_assert(dd.name == "buttonrpc is good");
buttont_assert(dd.height == 180);
int foo6r = client.call<int>("foo_6", 10, "buttonrpc", 100).val();
buttont_assert(foo6r == 1000);
buttonrpc::value_t<void> xx = client.call<void>("foo_7", 666);
buttont_assert(!xx.valid());
#ifdef _WIN32
Sleep(1000);
#else
sleep(1);
#endif
}
return 0;
}