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:
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 
XmlRpc::XmlRpcServer
A class to handle XML RPC requests.
Definition: XmlRpcServer.h:41
XmlRpc::XmlRpcValue::BinaryData
std::vector< char > BinaryData
Definition: XmlRpcValue.h:41
XmlRpc
Definition: XmlRpcClient.h:20
TestBase64
Definition: TestBase64Server.cpp:22
s
XmlRpcServer s
Definition: TestBase64Server.cpp:19
TestBase64::execute
void execute(XmlRpcValue &params, XmlRpcValue &result)
Execute the method. Subclasses must provide a definition for this method.
Definition: TestBase64Server.cpp:27
TestBase64::TestBase64
TestBase64(XmlRpcServer *s)
Definition: TestBase64Server.cpp:25
XmlRpc::XmlRpcServerMethod
Abstract class representing a single RPC method.
Definition: XmlRpcServerMethod.h:26
XmlRpc.h
main
int main(int argc, char *argv[])
Definition: TestBase64Server.cpp:50
XmlRpc::XmlRpcServer::bindAndListen
bool bindAndListen(int port, int backlog=5)
Definition: XmlRpcServer.cpp:107
TestBase64
TestBase64(XmlRpcServer *s)
Definition: TestBase64Server.cpp:21
XmlRpc::XmlRpcServer::work
void work(double msTime)
Process client requests for the specified time.
Definition: XmlRpcServer.cpp:163
XmlRpc::XmlRpcValue
RPC method arguments and results are represented by Values.
Definition: XmlRpcValue.h:24


xmlrpcpp
Author(s): Chris Morley, Konstantin Pilipchuk, Morgan Quigley, Austin Hendrix, Dirk Thomas , Jacob Perron
autogenerated on Thu Nov 23 2023 04:01:41