RpcXmlServer.pl - RPC::XML Server Sample Program

This section provides a tutorial example on how to write a RPC::XML server sample program, RpcXmlServer.pl, supporting 3 remote methods: com.herong.hello, com.herong.getCelsius, and com.herong.getInfo.

To test RPC::XML, I wrote the following the sample server program, RpcXmlServer.pl:

#- RpcXmlServer.pl
#- Copyright (c) HerongYang.com. All Rights Reserved.

   use RPC::XML;
   use RPC::XML::Server;
   my $host = "localhost";
   my $port = "8001";
   my $daemon = RPC::XML::Server->new(host => $host, port => $port);
   print "Adding com.herong.hello...\n";
   $daemon->add_method({ name => 'com.herong.hello',
      signature => ['string'],
      code => sub {return "Hello world!";} });
   print "Adding com.herong.getCelsius...\n";
   my @sig = ('double', 'double double');
   $daemon->add_method({ name => 'com.herong.getCelsius',
      signature => \@sig, code => \&getCelsius });
   print "Adding com.herong.getInfo...\n";
   $daemon->add_method({ name => 'com.herong.getInfo',
      signature => ['array'], code => \&getInfo });
   print "Listening at $host:$port...\n";
sub getCelsius {
   my $s = shift; # The first parameter is the server object
   my $f = shift;
   $f = 0.0 unless $f;
   print "getCelsius called with ".$f."...\n";
   return ($f-32.0)/1.8;
sub getInfo {
   my @info = ("Author","Herong Yang", "Version", "2005");
   return \@info;

Of course, this is a very simple XML-RPC server:

If you run the RpcXmlServer.pl in a command window, you will see:

Adding com.herong.hello...
Adding com.herong.getCelsius...
Adding com.herong.getInfo...
Listening at localhost:8001...

Table of Contents

 About This Book

 Perl on Linux Systems

 ActivePerl on Windows Systems

 Data Types: Values and Variables

 Expressions, Operations and Simple Statements

 User Defined Subroutines

 Perl Built-in Debugger

 Name Spaces and Perl Module Files

 Symbolic (or Soft) References

 Hard References - Addresses of Memory Objects

 Objects (or References) and Classes (or Packages)

 Typeglob and Importing Identifiers from Other Packages

 String Built-in Functions and Performance

 File Handles and Data Input/Output

 Open Files in Binary Mode

 Open Directories and Read File Names

 File System Functions and Operations

 Image and Picture Processing

 Using DBM Database Files

 Using MySQL Database Server

 Socket Communication Over the Internet

 XML::Simple Module - XML Parser and Generator

 XML Communication Model

 SOAP::Lite - SOAP Server-Client Communication Module

 Perl Programs as IIS Server CGI Scripts

 CGI (Common Gateway Interface)

 XML-RPC - Remote Procedure Call with XML and HTTP

RPC::XML - Perl Implementation of XML-RPC

 What Is RPC::XML?

 RPC::XML::Server - XML-RPC Server Interface Class

 RPC::XML Client and Data Classes

 Installing NMake 1.5

 Installing RPC::XML Module

RpcXmlServer.pl - RPC::XML Server Sample Program

 RpcXmlClient.pl - RPC::XML Client Sample Program

 Sending Arrays with Remote Method Calls

 Integrating Perl with Apache Web Server

 CGI.pm Module for Building Web Pages

 LWP::UserAgent and Web Site Testing

 Converting Perl Script to Executable Binary

 Managing Perl Engine and Modules on macOS

 Archived Tutorials


 Full Version in PDF/EPUB