initial load of upstream version 1.06.32
[xmlrpc-c] / examples / cpp / xmlrpc_sample_add_client.cpp
1 #include <cstdlib>
2 #include <string>
3 #include <iostream>
4 #include <xmlrpc-c/girerr.hpp>
5 #include <xmlrpc-c/base.hpp>
6 #include <xmlrpc-c/client_simple.hpp>
7
8 using namespace std;
9
10 int
11 main(int argc, char **) {
12
13     if (argc-1 > 0) {
14         cerr << "This program has no arguments" << endl;
15         exit(1);
16     }
17
18     try {
19         string const serverUrl("http://localhost:8080/RPC2");
20         string const methodName("sample.add");
21
22         xmlrpc_c::clientSimple myClient;
23         xmlrpc_c::value result;
24         
25         myClient.call(serverUrl, methodName, "ii", &result, 5, 7);
26
27         int const sum = xmlrpc_c::value_int(result);
28             // Assume the method returned an integer; throws error if not
29
30         cout << "Result of RPC (sum of 5 and 7): " << sum << endl;
31
32     } catch (girerr::error const error) {
33         cerr << "Client threw error: " << error.what() << endl;
34     } catch (...) {
35         cerr << "Client threw unexpected error." << endl;
36     }
37
38     return 0;
39 }