Beschreibe hier die neue Seite. |
XMLRPC Spielereien die ich irgendwann mal in meinem lokalem Wiki erfasst habe == XML RPC in perl == XMLRPC Simple daemon [[Code] #!/usr/bin/perl use Frontier::Daemon; sub sumAndDifference { my ($x, $y) = @_; return {'sum' => $x + $y, 'difference' => $x - $y}; } # Call me as ![]() $methods = {'sample.sumAndDifference' => \&sumAndDifference}; Frontier::Daemon->new(LocalPort? => 8081, methods => $methods) or die "Couldn't start HTTP server: $!"; ] XMLRPC Simple client [[Code] use Frontier::Client; # Make an object to represent the XML-RPC server. $server_url = ' ![]() $server = Frontier::Client->new(url => $server_url); # Call the remote server and get our result. $result = $server->call('sample.sumAndDifference', 5, 3); $sum = $result->{'sum'}; $difference = $result->{'difference'}; print "Sum: $sum, Difference: $difference\n"; ] == xmlrpc in C == [[Code] #include <stdio.h> #include <xmlrpc.h> #include <xmlrpc_abyss.h> xmlrpc_value * sample_add (xmlrpc_env *env, xmlrpc_value *param_array, void *user_data) { xmlrpc_int32 x, y, z; /* Parse our argument array. */ xmlrpc_parse_value(env, param_array, "(ii)", &x, &y); if (env->fault_occurred) return NULL; /* Add our two numbers. */ z = x + y; /* Return our result. */ return xmlrpc_build_value(env, "i", z); } int main (int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Usage: servertest abyss.conf\n"); exit(1); } xmlrpc_server_abyss_init({XMLRPC SERVER ABYSS NO FLAGS}?, argv[1]); xmlrpc_server_abyss_add_method("sample.add", &sample_add, NULL); printf("server: switching to background.\n"); xmlrpc_server_abyss_run(); } ] config file: [[Code] # ABYSS Web Server configuration file # (C) Moez Mahfoudh - 2000 # Cases in option names are ignored, # that means that PORT=port=PoRT?=.. # When writing paths, do not worry about / or \ use. # ABYSS will substitute / with \ on Win32 systems. # Options which are system specific (such as User) are # ignored on systems which do not handle them. # The Port option tells the server on which TCP port to listen. # default is 80 Port 8000 # The name or #number of the user to run the server as if it is # launched as root (UNIX specific) User nobody # The Server Root (UNIX systems style) ServerRoot? /var/www/ # The Server Root (Win32 systems style) # ServerRoot? c:\abyss # The Path option specifies the web files path. Path /var/www # htdocs # The Default option contains the name of the files the server should # look for when only a path is given (e.g. ![]() Default index.html index.htm INDEX.HTM INDEX.HTML # The KeepAlive? option is used to set the maximum number of requests # served using the same persistent connection. KeepAlive? 10 # The TimeOut? option tells the server how much seconds to wait for # an idle connection before closing it. TimeOut? 10 # The MimeTypes? option specifies the location of the file # containing the mapping of MIME types and files extensions MimeTypes? mime.types # The path of the log file LogFile? access.log # The file where the pid of the server is logged (UNIX specific) PidFile? abyss.pid # If AdvertiseServer? if set to no, then no server field would be # appended to the responses. This is the way to make the server # identity unknown to some malicious people which can profit from # well known security holes in the software to crash it. AdvertiseServer? yes ] client for that server in perl: [[Code] use Frontier::Client; # Make an object to represent the XML-RPC server. $server_url = ' ![]() $server = Frontier::Client->new(url => $server_url); # Call the remote server and get our result. $result = $server->call('sample.add', 5, 3); print "Sum: $result\n"; ] |
XML RPC in perl | ![]() |
![]() |
|
XMLRPC Simple client
![]() |
|
xmlrpc in C | ![]() |
![]() |
|
config file:
![]() |
|
client for that server in perl:
![]() |
|