You are here: XML-RPC « PHP Programming Language « IT news, forums, messages
XML-RPC

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация