HelloClient.cpp
Go to the documentation of this file.
00001 // HelloClient.cpp : A simple xmlrpc client. Usage: HelloClient serverHost serverPort
00002 // Link against xmlrpc lib and whatever socket libs your system needs (ws2_32.lib 
00003 // on windows)
00004 #include "XmlRpc.h"
00005 #include <iostream>
00006 using namespace XmlRpc;
00007 
00008 int main(int argc, char* argv[])
00009 {
00010   if (argc != 3) {
00011     std::cerr << "Usage: HelloClient serverHost serverPort\n";
00012     return -1;
00013   }
00014   int port = atoi(argv[2]);
00015   //XmlRpc::setVerbosity(5);
00016 
00017   // Use introspection API to look up the supported methods
00018   XmlRpcClient c(argv[1], port);
00019   XmlRpcValue noArgs, result;
00020   for (int i = 0; i < 2000; i++)
00021   {
00022     if (c.execute("system.listMethods", noArgs, result))
00023       std::cout << "\nMethods:\n " << result << "\n\n";
00024     else
00025       std::cout << "Error calling 'listMethods'\n\n";
00026   }
00027 
00028   // Use introspection API to get the help string for the Hello method
00029   XmlRpcValue oneArg;
00030   oneArg[0] = "Hello";
00031   if (c.execute("system.methodHelp", oneArg, result))
00032     std::cout << "Help for 'Hello' method: " << result << "\n\n";
00033   else
00034     std::cout << "Error calling 'methodHelp'\n\n";
00035 
00036   // Call the Hello method
00037   if (c.execute("Hello", noArgs, result))
00038     std::cout << result << "\n\n";
00039   else
00040     std::cout << "Error calling 'Hello'\n\n";
00041 
00042   // Call the HelloName method
00043   oneArg[0] = "Chris";
00044   if (c.execute("HelloName", oneArg, result))
00045     std::cout << result << "\n\n";
00046   else
00047     std::cout << "Error calling 'HelloName'\n\n";
00048 
00049   // Add up an array of numbers
00050   XmlRpcValue numbers;
00051   numbers[0] = 33.33;
00052   numbers[1] = 112.57;
00053   numbers[2] = 76.1;
00054   std::cout << "numbers.size() is " << numbers.size() << std::endl;
00055   if (c.execute("Sum", numbers, result))
00056     std::cout << "Sum = " << double(result) << "\n\n";
00057   else
00058     std::cout << "Error calling 'Sum'\n\n";
00059 
00060   // Test the "no such method" fault
00061   if (c.execute("NoSuchMethod", numbers, result))
00062     std::cout << "NoSuchMethod call: fault: " << c.isFault() << ", result = " << result << std::endl;
00063   else
00064     std::cout << "Error calling 'Sum'\n";
00065 
00066   // Test the multicall method. It accepts one arg, an array of structs
00067   XmlRpcValue multicall;
00068   multicall[0][0]["methodName"] = "Sum";
00069   multicall[0][0]["params"][0] = 5.0;
00070   multicall[0][0]["params"][1] = 9.0;
00071 
00072   multicall[0][1]["methodName"] = "NoSuchMethod";
00073   multicall[0][1]["params"][0] = "";
00074 
00075   multicall[0][2]["methodName"] = "Sum";
00076   // Missing params
00077 
00078   multicall[0][3]["methodName"] = "Sum";
00079   multicall[0][3]["params"][0] = 10.5;
00080   multicall[0][3]["params"][1] = 12.5;
00081 
00082   if (c.execute("system.multicall", multicall, result))
00083     std::cout << "\nmulticall  result = " << result << std::endl;
00084   else
00085     std::cout << "\nError calling 'system.multicall'\n";
00086 
00087   return 0;
00088 }


xmlrpcpp
Author(s): Chris Morley and Konstantin Pilipchuk, slight modifications and ROS wrapping by Morgan Quigley
autogenerated on Sat Dec 28 2013 17:42:59