|
Posted by Chris on 07/24/06 12:59
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
---------------------------------------
<?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" =>
"sumAndDifference")));
}
?>
//--------------------------------------------- client.php
---------------------------------------
<?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() . ": " .
$result->faultString();
} 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.
Thanks,
Chris
[Back to original message]
|