Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi all,

I'm trying to build a sample XML-RPC using PHP,  but can't get the
sample working.
Can experienced users tell me why?

//--------------------------------------------- server.php

include 'xmlrpc.inc';
include 'xmlrpcs.inc';

function sumAndDifference ($params) {

    // Parse our parameters.
    $xval = $params->getParam(0);
    $x = $xval->scalarval();
    $yval = $params->getParam(1);
    $y = $yval->scalarval();

    // Build our response.
    $struct = array('sum' => new xmlrpcval($x + $y, 'int'),
                    'difference' => new xmlrpcval($x - $y, 'int'));
    return new xmlrpcresp(new xmlrpcval($struct, 'struct'));

while(1) {
new xmlrpc_server(array("sumAndDifference" => array("function" =>

//--------------------------------------------- client.php

include 'xmlrpc.inc';

// Make an object to represent our server.
$server = new xmlrpc_client("/xmlrpc/server.php", "localhost", 80);
// Send a message to the server.
$message = new xmlrpcmsg("sample.sumAndDifference",array(new
xmlrpcval(5, 'int'),new xmlrpcval(3, 'int')));
$result = $server->send($message);

// Process the response.
if (!$result) {
    print "Could not connect to server\n";
} elseif ($result->faultCode()) {
    print "XML-RPC Fault #" . $result->faultCode() . ": " .
} else {
    $struct = $result->value();
    $sumval = $struct->structmem('sum');
    $sum = $sumval->scalarval();
    $differenceval = $struct->structmem('difference');
    $difference = $differenceval->scalarval();
    print "Sum: " . $sum .
        ", Difference: " . $difference;

I have to run this code on Linux. Please tell me how to run the client
and server. I am using php client/server.php to run my programs.

Kindly let me know the solution.



Quoted text here. Click to load it

 You didn't post what error messages you are getting.

Quoted text here. Click to load it

 These aren't the names of the XML_RPC include files for starters, so go back
to the manual and copy out the examples again:


Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

Site Timeline