|
Frequently Asked Questions
-
What is XmlRpc++?
XmlRpc++ is a C++ implementation
of the XML-RPC protocol.
-
What is XML-RPC?
The XML-RPC protocol was designed to make
remote procedure calls (RPCs) easy: it encodes data in a simple
XML format and uses HTTP for
communication. XML-RPC is intended to be used to implement web services and
distributed applications. Check out
XML-RPC for Newbies.
-
What other XML-RPC implementations exist?
XML-RPC
implementations
-
Why do we need another XML-RPC implementation (specifically XmlRpc++)?
XmlRpc++ is designed to make it easy to incorporate XML-RPC client and server
support into C++ applications. It is written in portable, extendable C++. No
other libraries are required, other than your system's socket libraries. Simple
XML parsing and HTTP support are built in. It is easy to build and has a small
API. There is no easier way to add remote procedure call support to a C++
application that I know of.
-
Why not use SOAP (or DCE RPC, ONC RPC, CORBA, DCOM, ...)?
XML-RPC is easy, free, and fast enough for my purposes. Use the tool that
best solves your problem.
-
What is an XML-RPC server (client)?
An XML-RPC server has one or more procedures (or methods) registered, and makes
those procedures available to XML-RPC clients over a network (LAN or Internet).
An XML-RPC client calls one or more remote procedures provided by an XML-RPC
server, and gets a result, much like calling a local procedure (function,
method, etc). Arguments and results are converted to an XML format for transfer
across the network.
-
How do you use XmlRpc++ as an XML-RPC client?
Here is an example of a client (taken from the file test/HelloClient.cpp in the
XmlRpc++ distribution) that gets a server hostname and port number from the
command line and calls a remote procedure named Hello, then prints the result:
#include "XmlRpc.h"
#include <iostream>
using namespace XmlRpc;
int main(int argc, char* argv[]) {
if (argc != 3) {
std::cerr << "Usage: HelloClient serverHost serverPort\n";
return -1;
}
const char* hostname = argv[1];
int port = atoi(argv[2]);
// Create a client and connect to the server at hostname:port
XmlRpcClient c(hostname, port);
XmlRpcValue noArgs, result;
// Call the remote procedure Hello and print the result value
if (c.execute("Hello", noArgs, result))
std::cout << result << std::endl;
}
-
How do you use XmlRpc++ as an XML-RPC server?
Here is an example of a server (taken from the file test/HelloServer.cpp in the
XmlRpc++ distribution) that registers a single remote procedure named Hello and
listens on a port for calls to that procedure:
#include "XmlRpc.h"
using namespace XmlRpc;
// The server
XmlRpcServer s;
// The Hello method. No arguments, result is "Hello".
class Hello : public XmlRpcServerMethod
{
public:
Hello(XmlRpcServer* s) : XmlRpcServerMethod("Hello", s) {}
void execute(XmlRpcValue& params, XmlRpcValue& result)
{
result = "Hello";
}
} hello(&s); // This constructor registers the method with the server
// The port to use
const int PORT = 8080;
int main(int argc, char* argv[]) {
// Create the server socket on the specified port
s.bindAndListen(PORT);
// Wait for requests and process indefinitely (Ctrl-C to exit)
s.work(-1.0);
return 0;
}
|