1.

How Do You Use Xmlrpc++ As An Xml-rpc Server?

Answer»

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;

}

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;

}



Discussion

No Comment Found