TestBase64Server.cpp
Go to the documentation of this file.
1 // TestBase64Server.cpp : Simple XMLRPC server example. Usage: TestBase64Server serverPort
2 //
3 #if defined(_MSC_VER)
4 # pragma warning(disable:4786) // identifier was truncated in debug info
5 #endif
6 
7 
8 #include <iostream>
9 #include <fstream>
10 #include <algorithm>
11 #include <stdlib.h>
12 
13 
14 #include "xmlrpcpp/XmlRpc.h"
15 using namespace XmlRpc;
16 
17 
18 // The server
20 
21 // No arguments, result is Base64-encoded pngnow.png data.
23 {
24 public:
25  TestBase64(XmlRpcServer* s) : XmlRpcServerMethod("TestBase64", s) {}
26 
27  void execute(XmlRpcValue& params, XmlRpcValue& result)
28  {
29  std::ifstream infile("pngnow.png", std::ios::binary);
30  if (infile.fail())
31  infile.open("../pngnow.png", std::ios::binary);
32  if (infile.fail())
33  result = "Could not open file pngnow.png";
34  else {
35 
36  XmlRpcValue::BinaryData& data = result;
37  int n = 0;
38  for (;; ++n) {
39  char c = infile.get();
40  if (infile.eof()) break;
41  data.push_back(c);
42  }
43  std::cerr << "Read " << n << " bytes from pngnow.png\n";
44  }
45  }
46 } TestBase64(&s); // This constructor registers the method with the server
47 
48 
49 
50 int main(int argc, char* argv[])
51 {
52  if (argc != 2) {
53  std::cerr << "Usage: TestBase64Server serverPort\n";
54  return -1;
55  }
56  int port = atoi(argv[1]);
57 
58  //XmlRpc::setVerbosity(5);
59 
60  // Create the server socket on the specified port
61  s.bindAndListen(port);
62 
63  // Wait for requests indefinitely
64  s.work(-1.0);
65 
66  return 0;
67 }
68 
Definition: XmlRpc.h:39
void execute(XmlRpcValue &params, XmlRpcValue &result)
Execute the method. Subclasses must provide a definition for this method.
RPC method arguments and results are represented by Values.
Definition: XmlRpcValue.h:24
int main(int argc, char *argv[])
void work(double msTime)
Process client requests for the specified time.
bool bindAndListen(int port, int backlog=5)
TestBase64(XmlRpcServer *s)
Abstract class representing a single RPC method.
A class to handle XML RPC requests.
Definition: XmlRpcServer.h:37
TestBase64(XmlRpcServer *s)
std::vector< char > BinaryData
Definition: XmlRpcValue.h:41
XmlRpcServer s


xmlrpcpp
Author(s): Chris Morley, Konstantin Pilipchuk, Morgan Quigley, Austin Hendrix, Dirk Thomas
autogenerated on Mon Nov 2 2020 03:52:24