File: TestBase64Client.cpp

package info (click to toggle)
ros-ros-comm 1.17.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 12,008 kB
  • sloc: cpp: 41,963; python: 38,967; xml: 2,663; ansic: 2,384; sh: 274; makefile: 27
file content (45 lines) | stat: -rw-r--r-- 1,235 bytes parent folder | download | duplicates (5)
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
// TestBase64Client.cpp : A simple xmlrpc client that returns a png file
// encoded as base64 data to the client.
//
// Usage: TestBase64Client serverHost serverPort outputfile
// Requests a png file from the specified server and saves it in outputfile.
// Link against xmlrpc lib and whatever socket libs your system needs (ws2_32.lib on windows)

#include "xmlrpcpp/XmlRpc.h"
#include <iostream>
#include <fstream>
#include <stdlib.h>

using namespace XmlRpc;

int main(int argc, char* argv[])
{
  if (argc != 4) {
    std::cerr << "Usage: TestBase64Client serverHost serverPort outputFile\n";
    return -1;
  }
  int port = atoi(argv[2]);

  //XmlRpc::setVerbosity(5);
  XmlRpcClient c(argv[1], port);

  XmlRpcValue noArgs, result;
  if (c.execute("TestBase64", noArgs, result))
  {
    const XmlRpcValue::BinaryData& data = result;
    std::ofstream outfile(argv[3], std::ios::binary | std::ios::trunc);
    if (outfile.fail())
      std::cerr << "Error opening " << argv[3] << " for output.\n";
    else
    {
      int n = int(data.size());
      for (int i=0; i<n; ++i)
        outfile << data[i];
    }
  }
  else
    std::cout << "Error calling 'TestBase64'\n\n";

  return 0;
}