Menu

Sending arrays from server to client

Help
2003-02-18
2003-02-20
  • Ben Hornedo

    Ben Hornedo - 2003-02-18

    I'm trying to get my XML-RPC server to send a collection of information back to the client. Like a phone book:

    firstame, lastname, phone

    Has anyone done this? Is there a limit to the size of the response sent back to the client? Most of the tests demonstrate how to pass arrays to the server, but nothing on how to pass an array back to the client.

    Any info would be great.

     
    • Chris Morley

      Chris Morley - 2003-02-20

      Anything that you can stuff into the result XmlRpcValue is passed
      back to the client, so you can steal code from any of the examples
      that pass arrays to the server.

      What isn't working correctly? Arrays need the size specified up front,
      that may be the problem. Its easy to change that to grow the array
      dynamically, but it would be less efficient. Depending upon the
      return type of your query[] operator and your compiler you may
      need to provide more explicit type information, eg:

      // The structs are indexed using std::string, so you are better
      // off constructing them once and re-using them. Using char* as
      // an index simply invokes the implicit conversion to std::string.
      const std::string TAG_FIRSTNAME("firstname");
      const std::string TAG_LASTNAME("lastname");
      const std::string TAG_PHONE("phone");

      result.setSize(recordCount);
      for (int c=0; c<recordCount;c++) {
      result[c][TAG_FIRSTNAME] = std::string(query[TAG_FIRSTNAME]);
      result[c][TAG_LASTNAME] = std::string(query[TAG_LASTNAME]);
      result[c][TAG_PHONE] = std::string(query[TAG_PHONE]);
      }

      You may need query[TAG_FIRSTNAME.c_str()] etc if your maps are
      keyed on char*.

       

Log in to post a comment.