Markus Rechberger / xmlrpc
 
StartSeite | MarkusRechberger/ | Neues | TestSeite | ForumSeite | Teilnehmer | Kategorien | Index | Hilfe | Einstellungen | Ändern

XMLRPC Spielereien die ich irgendwann mal in meinem lokalem Wiki erfasst habe

XML RPC in perl
XMLRPC Simple daemon
#!/usr/bin/perl
use Frontier::Daemon;

sub sumAndDifference {
    my ($x, $y) = @_;
    return {'sum' => $x + $y, 'difference' => $x - $y};
}

# Call me as http://localhost:8080/RPC2
$methods = {'sample.sumAndDifference' => \&sumAndDifference};
Frontier::Daemon->new(LocalPort => 8081, methods => $methods)
    or die "Couldn't start HTTP server: $!";

XMLRPC Simple client
use Frontier::Client;

# Make an object to represent the XML-RPC server.
$server_url = 'http://localhost:8081/RPC2';
$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

#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:
# 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. http://myserver/info/).
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:
use Frontier::Client;

# Make an object to represent the XML-RPC server.
$server_url = 'http://localhost:8000/RPC2';
$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";


StartSeite | MarkusRechberger/ | Neues | TestSeite | ForumSeite | Teilnehmer | Kategorien | Index | Hilfe | Einstellungen | Ändern
Text dieser Seite ändern (zuletzt geändert: 12. Oktober 2004 23:57 (diff))
Suchbegriff: gesucht wird
im Titel
im Text