forked from spillz/codeblocks-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelloClient.cpp
More file actions
124 lines (116 loc) · 3.81 KB
/
Copy pathHelloClient.cpp
File metadata and controls
124 lines (116 loc) · 3.81 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// HelloClient.cpp : A simple xmlrpc client. Usage: HelloClient serverHost serverPort
// Link against xmlrpc lib and whatever socket libs your system needs (ws2_32.lib
// on windows)
#include "XmlRpc.h"
#include <iostream>
using namespace XmlRpc;
int main(int argc, char* argv[])
{
if (argc != 3) {
std::cerr << "Usage: HelloClient serverHost serverPort\n";
return -1;
}
int port = atoi(argv[2]);
//XmlRpc::setVerbosity(5);
// Use introspection API to look up the supported methods
XmlRpcClient c(argv[1], port);
XmlRpcValue noArgs, result;
if (c.execute("system.listMethods", noArgs, result))
std::cout << "\nMethods:\n " << result << "\n\n";
else
std::cout << "Error calling 'listMethods'\n\n";
//// // Use introspection API to get the help string for the Hello method
// XmlRpcValue oneArg;
// oneArg[0] = "exec";
// if (c.execute("system.methodSignature", oneArg, result))
// std::cout << "Help for 'Hello' method: " << result << "\n\n";
// else
// std::cout << "Error calling 'methodHelp'\n\n";
// Add up an array of numbers
XmlRpcValue numbers;
numbers[0] = "print 1";
numbers[1] = "";
if (c.execute("run_code", numbers, result))
{
std::cout << result.size();
std::cout << "run_code result = " << "return code: "<<result[0]<<"\n stdout:" << result[1]<<"\n stderr:" << result[2]<< "\n\n";
}
else
{
std::cout << "Error calling 'run_code'\n\n";
exit(1);
}
while(int(result[0])>0)
if(c.execute("cont", numbers, result))
{
std::cout << result.size();
std::cout << "cont result = " << int(result[0]) << result[1] << result[2] << "\n\n";
}
else
std::cout << "Error calling 'cont'\n\n";
if (c.execute("end", noArgs, result))
std::cout << "end result = " << result<< "\n\n";
else
std::cout << "Error calling 'end'\n\n";
//
//
// // Use introspection API to get the help string for the Hello method
// XmlRpcValue oneArg;
// oneArg[0] = "Hello";
// if (c.execute("system.methodHelp", oneArg, result))
// std::cout << "Help for 'Hello' method: " << result << "\n\n";
// else
// std::cout << "Error calling 'methodHelp'\n\n";
//
// // Call the Hello method
// if (c.execute("Hello", noArgs, result))
// std::cout << result << "\n\n";
// else
// std::cout << "Error calling 'Hello'\n\n";
//
// // Call the HelloName method
// oneArg[0] = "Chris";
// if (c.execute("HelloName", oneArg, result))
// std::cout << result << "\n\n";
// else
// std::cout << "Error calling 'HelloName'\n\n";
//
// // Add up an array of numbers
// XmlRpcValue numbers;
// numbers[0] = 33.33;
// numbers[1] = 112.57;
// numbers[2] = 76.1;
// std::cout << "numbers.size() is " << numbers.size() << std::endl;
// if (c.execute("Sum", numbers, result))
// std::cout << "Sum = " << double(result) << "\n\n";
// else
// std::cout << "Error calling 'Sum'\n\n";
//
// // Test the "no such method" fault
// if (c.execute("NoSuchMethod", numbers, result))
// std::cout << "NoSuchMethod call: fault: " << c.isFault() << ", result = " << result << std::endl;
// else
// std::cout << "Error calling 'Sum'\n";
//
// // Test the multicall method. It accepts one arg, an array of structs
// XmlRpcValue multicall;
// multicall[0][0]["methodName"] = "Sum";
// multicall[0][0]["params"][0] = 5.0;
// multicall[0][0]["params"][1] = 9.0;
//
// multicall[0][1]["methodName"] = "NoSuchMethod";
// multicall[0][1]["params"][0] = "";
//
// multicall[0][2]["methodName"] = "Sum";
// // Missing params
//
// multicall[0][3]["methodName"] = "Sum";
// multicall[0][3]["params"][0] = 10.5;
// multicall[0][3]["params"][1] = 12.5;
//
// if (c.execute("system.multicall", multicall, result))
// std::cout << "\nmulticall result = " << result << std::endl;
// else
// std::cout << "\nError calling 'system.multicall'\n";
return 0;
}