Menu

Recieving Arrays

Help
Anonymous
2003-01-28
2003-01-28
  • Anonymous

    Anonymous - 2003-01-28

    Hi,
    I have been using this library for the last couple of weeks and I like it very much.  It is very clean and lightweight.  My thanks to the author.
    I was wondering if anyone has a sample code for recieving an array of ints if I am running the server.
    thanks a lot.

     
    • Chris Morley

      Chris Morley - 2003-01-28

      There are some examples of similar methods in the Validator example program, but you want to do something like this:

      // A server method that accepts one argument,
      // which is an array of ints.
      // It returns the sum of the ints.

      class SumOfInts : public XmlRpcServerMethod
      {
      public:
        SumOfInts(XmlRpcServer* s) : XmlRpcServerMethod("SumOfInts", s) {}

        void execute(XmlRpcValue& params, XmlRpcValue& result)
        {
          int n = params[0].size(), sum = 0;
          for (int i=0; i<n; ++i)
            sum += int(params[0][i]);

          result = sum;
        }
      };

      Chris

       

Log in to post a comment.