XML-RPC

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris

    #1

    XML-RPC

    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 sumAndDifferenc e ($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($stru ct, 'struct'));
    }

    while(1) {
    new xmlrpc_server(a rray("sumAndDif ference" =array("functio n" =>
    "sumAndDifferen ce")));
    }
    ?>

    //--------------------------------------------- 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("samp le.sumAndDiffer ence",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('dif ference');
    $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

  • Andy Hassall

    #2
    Re: XML-RPC

    On 24 Jul 2006 05:59:57 -0700, "Chris" <kirany82@gmail .comwrote:
    >I'm trying to build a sample XML-RPC using PHP, but can't get the
    >sample working.
    >Can experienced users tell me why?
    You didn't post what error messages you are getting.
    <?php
    include 'xmlrpc.inc';
    include 'xmlrpcs.inc';
    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.u k :: http://www.andyh.co.uk
    http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

    Comment

    Working...