TestBase64Server.cpp
Go to the documentation of this file.
00001 // TestBase64Server.cpp : Simple XMLRPC server example. Usage: TestBase64Server serverPort
00002 //
00003 #if defined(_MSC_VER)
00004 # pragma warning(disable:4786)    // identifier was truncated in debug info
00005 #endif
00006 
00007 
00008 #include <iostream>
00009 #include <fstream>
00010 #include <algorithm>
00011 #include <stdlib.h>
00012 
00013 
00014 #include "XmlRpc.h"
00015 using namespace XmlRpc;
00016 
00017 
00018 // The server
00019 XmlRpcServer s;
00020 
00021 // No arguments, result is Base64-encoded pngnow.png data.
00022 class TestBase64 : public XmlRpcServerMethod
00023 {
00024 public:
00025   TestBase64(XmlRpcServer* s) : XmlRpcServerMethod("TestBase64", s) {}
00026 
00027   void execute(XmlRpcValue& params, XmlRpcValue& result)
00028   {
00029     std::ifstream infile("pngnow.png", std::ios::binary);
00030     if (infile.fail())
00031       infile.open("../pngnow.png", std::ios::binary);
00032     if (infile.fail())
00033       result = "Could not open file pngnow.png";
00034     else {
00035 
00036       XmlRpcValue::BinaryData& data = result;
00037       int n = 0;
00038       for (;; ++n) {
00039         char c = infile.get();
00040         if (infile.eof()) break;
00041         data.push_back(c);
00042       }
00043       std::cerr << "Read " << n << " bytes from pngnow.png\n";
00044     }
00045   }
00046 } TestBase64(&s);    // This constructor registers the method with the server
00047 
00048 
00049 
00050 int main(int argc, char* argv[])
00051 {
00052   if (argc != 2) {
00053     std::cerr << "Usage: TestBase64Server serverPort\n";
00054     return -1;
00055   }
00056   int port = atoi(argv[1]);
00057 
00058   //XmlRpc::setVerbosity(5);
00059 
00060   // Create the server socket on the specified port
00061   s.bindAndListen(port);
00062 
00063   // Wait for requests indefinitely
00064   s.work(-1.0);
00065 
00066   return 0;
00067 }
00068 


xmlrpcpp
Author(s): Chris Morley, Konstantin Pilipchuk, Morgan Quigley
autogenerated on Tue Mar 7 2017 03:44:43