| 1 |
// HelloClient.cpp : A simple xmlrpc client. Usage: HelloClient serverHost serverPort |
| 2 |
// Link against xmlrpc lib and whatever socket libs your system needs (ws2_32.lib |
| 3 |
// on windows) |
| 4 |
#include "XmlRpc.h" |
| 5 |
#include <iostream> |
| 6 |
#include <stdlib.h> |
| 7 |
|
| 8 |
using namespace XmlRpc; |
| 9 |
|
| 10 |
int main(int argc, char* argv[]) |
| 11 |
{ |
| 12 |
if (argc != 3) { |
| 13 |
std::cerr << "Usage: HelloClient serverHost serverPort\n"; |
| 14 |
return -1; |
| 15 |
} |
| 16 |
int port = atoi(argv[2]); |
| 17 |
//XmlRpc::setVerbosity(5); |
| 18 |
|
| 19 |
// Use introspection API to look up the supported methods |
| 20 |
XmlRpcClient c(argv[1], port); |
| 21 |
XmlRpcValue noArgs, result; |
| 22 |
if (c.execute("system.listMethods", noArgs, result)) |
| 23 |
std::cout << "\nMethods:\n " << result << "\n\n"; |
| 24 |
else |
| 25 |
std::cout << "Error calling 'listMethods'\n\n"; |
| 26 |
|
| 27 |
// Use introspection API to get the help string for the Hello method |
| 28 |
XmlRpcValue oneArg; |
| 29 |
oneArg[0] = "Hello"; |
| 30 |
if (c.execute("system.methodHelp", oneArg, result)) |
| 31 |
std::cout << "Help for 'Hello' method: " << result << "\n\n"; |
| 32 |
else |
| 33 |
std::cout << "Error calling 'methodHelp'\n\n"; |
| 34 |
|
| 35 |
// Call the Hello method |
| 36 |
if (c.execute("Hello", noArgs, result)) |
| 37 |
std::cout << result << "\n\n"; |
| 38 |
else |
| 39 |
std::cout << "Error calling 'Hello'\n\n"; |
| 40 |
|
| 41 |
// Call the HelloName method |
| 42 |
oneArg[0] = "Chris"; |
| 43 |
if (c.execute("HelloName", oneArg, result)) |
| 44 |
std::cout << result << "\n\n"; |
| 45 |
else |
| 46 |
std::cout << "Error calling 'HelloName'\n\n"; |
| 47 |
|
| 48 |
// Add up an array of numbers |
| 49 |
XmlRpcValue numbers; |
| 50 |
numbers[0] = 33.33; |
| 51 |
numbers[1] = 112.57; |
| 52 |
numbers[2] = 76.1; |
| 53 |
std::cout << "numbers.size() is " << numbers.size() << std::endl; |
| 54 |
if (c.execute("Sum", numbers, result)) |
| 55 |
std::cout << "Sum = " << double(result) << "\n\n"; |
| 56 |
else |
| 57 |
std::cout << "Error calling 'Sum'\n\n"; |
| 58 |
|
| 59 |
// Test the "no such method" fault |
| 60 |
if (c.execute("NoSuchMethod", numbers, result)) |
| 61 |
std::cout << "NoSuchMethod call: fault: " << c.isFault() << ", result = " << result << std::endl; |
| 62 |
else |
| 63 |
std::cout << "Error calling 'Sum'\n"; |
| 64 |
|
| 65 |
// Test the multicall method. It accepts one arg, an array of structs |
| 66 |
XmlRpcValue multicall; |
| 67 |
multicall[0][0]["methodName"] = "Sum"; |
| 68 |
multicall[0][0]["params"][0] = 5.0; |
| 69 |
multicall[0][0]["params"][1] = 9.0; |
| 70 |
|
| 71 |
multicall[0][1]["methodName"] = "NoSuchMethod"; |
| 72 |
multicall[0][1]["params"][0] = ""; |
| 73 |
|
| 74 |
multicall[0][2]["methodName"] = "Sum"; |
| 75 |
// Missing params |
| 76 |
|
| 77 |
multicall[0][3]["methodName"] = "Sum"; |
| 78 |
multicall[0][3]["params"][0] = 10.5; |
| 79 |
multicall[0][3]["params"][1] = 12.5; |
| 80 |
|
| 81 |
if (c.execute("system.multicall", multicall, result)) |
| 82 |
std::cout << "\nmulticall result = " << result << std::endl; |
| 83 |
else |
| 84 |
std::cout << "\nError calling 'system.multicall'\n"; |
| 85 |
|
| 86 |
return 0; |
| 87 |
} |