分类:
2006-10-21 20:29:11
include ("libphpxmlrpc/xmlrpc.inc"); include ("libphpxmlrpc/xmlrpcs.inc"); if ($_SERVER['REQUEST_METHOD'] != 'POST') exit(0); $add_sig = array(array($xmlrpcString, $xmlrpcInt, $xmlrpcInt)); $add_doc = "Add the two integer together"; function add($params) { global $xmlrpcerruser; $val = php_xmlrpc_decode($params); $ret = $val[0] + $val[1]; return new xmlrpcresp(new xmlrpcval($ret, "int")); } $server = new xmlrpc_server(array( "add" => array( "function" => "add", "signature" => $add_sig, "docstring" => $add_doc ))); ?> |
#!/bin/env python from xmlrpclib import * import sys # xmlrpc add sample in python server = Server("~xiaosuo/xmlrpc/xmlrpc_server.php"); try: retval = server.add(12, 13) print retval except Error, v: print "Error", v |
xiaosuo@gentux xmlrpc $ ./xmlrpc_client.py 25 |
include ("libphpxmlrpc/xmlrpc.inc"); include ("libphpxmlrpc/xmlrpcs.inc"); if (isset($_POST['var1']) && isset($_POST['var2'])) { $client = new xmlrpc_client("~xiaosuo/xmlrpc/xmlrpc_server.php"); $msg = new xmlrpcmsg("add", array( new xmlrpcval($_POST['var1'], "int"), new xmlrpcval($_POST['var2'], "int"))); $retval = &$client->send($msg); if ($retval->faultCode()) { print_r("An error occurred: "); print_r("Code: " . htmlspecialchars($retval->faultCode()) . " Reason: " . htmlspecialchars($retval->faultString())); } else { $sum = $retval->value()->scalarval(); } } ?> ""> |
#!/bin/bash xmlrpc ~xiaosuo/xmlrpc/xmlrpc_server.php add i/12 i/13 |
/* * Compile method: * gcc -o xmlrpc_client.out `xmlrpc-c-config --libs --cflags` xmlrpc_client.c -lxmlrpc_client */ #include #include #include #include #define NAME "XML-RPC C Test Client" #define VERSION "1.0" #define die_if_fault_occurred(x) \ do { \ if ((x)->fault_occurred) \ abort(); \ } while(0) int main(int const argc, const char ** const argv) { xmlrpc_env env; xmlrpc_value * resultP; int sum; char *const url = "~xiaosuo/xmlrpc/xmlrpc_server.php"; char *const methodName = "add"; /* Initialize our error-handling environment. */ xmlrpc_env_init(&env); /* Start up our XML-RPC client library. */ xmlrpc_client_init2(&env, XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION, NULL, 0); die_if_fault_occurred(&env); /* Make the remote procedure call */ resultP = xmlrpc_client_call(&env, url, methodName, "(ii)", (xmlrpc_int32) 12, (xmlrpc_int32) 13); die_if_fault_occurred(&env); /* Get our state name and print it out. */ xmlrpc_parse_value(&env, resultP, "i", &sum); die_if_fault_occurred(&env); printf("The sum is %d\n", sum); /* Dispose of our result value. */ xmlrpc_DECREF(resultP); /* Clean up our error-handling environment. */ xmlrpc_env_clean(&env); /* Shutdown our XML-RPC client library. */ xmlrpc_client_cleanup(); return 0; } |
#!/bin/env perl # use strict; use warnings; use Frontier::Client; my $server = Frontier::Client->new( url => "~xiaosuo/xmlrpc/xmlrpc_server.php"); my $sum = $server->call("add", (12, 13)); print $sum . "\n"; |