HelloClient.cpp
Go to the documentation of this file.
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 "xmlrpcpp/XmlRpc.h"
5 #include <iostream>
6 using namespace XmlRpc;
7 
8 int main(int argc, char* argv[])
9 {
10  if (argc != 3) {
11  std::cerr << "Usage: HelloClient serverHost serverPort\n";
12  return -1;
13  }
14  int port = atoi(argv[2]);
15  //XmlRpc::setVerbosity(5);
16 
17  // Use introspection API to look up the supported methods
18  XmlRpcClient c(argv[1], port);
19  XmlRpcValue noArgs, result;
20  for (int i = 0; i < 2000; i++)
21  {
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 
28  // Use introspection API to get the help string for the Hello method
29  XmlRpcValue oneArg;
30  oneArg[0] = "Hello";
31  if (c.execute("system.methodHelp", oneArg, result))
32  std::cout << "Help for 'Hello' method: " << result << "\n\n";
33  else
34  std::cout << "Error calling 'methodHelp'\n\n";
35 
36  // Call the Hello method
37  if (c.execute("Hello", noArgs, result))
38  std::cout << result << "\n\n";
39  else
40  std::cout << "Error calling 'Hello'\n\n";
41 
42  // Call the HelloName method
43  oneArg[0] = "Chris";
44  if (c.execute("HelloName", oneArg, result))
45  std::cout << result << "\n\n";
46  else
47  std::cout << "Error calling 'HelloName'\n\n";
48 
49  // Add up an array of numbers
50  XmlRpcValue numbers;
51  numbers[0] = 33.33;
52  numbers[1] = 112.57;
53  numbers[2] = 76.1;
54  std::cout << "numbers.size() is " << numbers.size() << std::endl;
55  if (c.execute("Sum", numbers, result))
56  std::cout << "Sum = " << double(result) << "\n\n";
57  else
58  std::cout << "Error calling 'Sum'\n\n";
59 
60  // Test the "no such method" fault
61  if (c.execute("NoSuchMethod", numbers, result))
62  std::cout << "NoSuchMethod call: fault: " << c.isFault() << ", result = " << result << std::endl;
63  else
64  std::cout << "Error calling 'Sum'\n";
65 
66  // Test the multicall method. It accepts one arg, an array of structs
67  XmlRpcValue multicall;
68  multicall[0][0]["methodName"] = "Sum";
69  multicall[0][0]["params"][0] = 5.0;
70  multicall[0][0]["params"][1] = 9.0;
71 
72  multicall[0][1]["methodName"] = "NoSuchMethod";
73  multicall[0][1]["params"][0] = "";
74 
75  multicall[0][2]["methodName"] = "Sum";
76  // Missing params
77 
78  multicall[0][3]["methodName"] = "Sum";
79  multicall[0][3]["params"][0] = 10.5;
80  multicall[0][3]["params"][1] = 12.5;
81 
82  if (c.execute("system.multicall", multicall, result))
83  std::cout << "\nmulticall result = " << result << std::endl;
84  else
85  std::cout << "\nError calling 'system.multicall'\n";
86 
87  return 0;
88 }
RPC method arguments and results are represented by Values.
Definition: XmlRpcValue.h:24
int size() const
Return the size for string, base64, array, and struct values.
bool isFault() const
Returns true if the result of the last execute() was a fault response.
Definition: XmlRpcClient.h:65
A class to send XML RPC requests to a server and return the results.
Definition: XmlRpcClient.h:26
bool execute(const char *method, XmlRpcValue const &params, XmlRpcValue &result)
int main(int argc, char *argv[])
Definition: HelloClient.cpp:8


xmlrpcpp
Author(s): Chris Morley, Konstantin Pilipchuk, Morgan Quigley, Austin Hendrix
autogenerated on Sun Feb 3 2019 03:29:51