Presentation is loading. Please wait.

Presentation is loading. Please wait.

CIS Distributed and Parallel Architectures

Similar presentations


Presentation on theme: "CIS Distributed and Parallel Architectures"— Presentation transcript:

1 CIS017-6 - Distributed and Parallel Architectures
XML-RPC – Introduction

2 01/12/2018 What is XML-RPC? XML-RPC.com Simple cross-platform distributed computing, based on the standards of the Internet. See:

3 01/12/2018 What is XML-RPC? It's a spec and a set of implementations that allow software running on disparate operating systems, running in different environments to make procedure calls over the Internet. It's remote procedure calling using HTTP as the transport and XML as the encoding. XML-RPC is designed to be as simple as possible, while allowing complex data structures to be transmitted, processed and returned. See: See:

4 Local Method Call (not distributed)
01/12/2018 Local Method Call (not distributed) public class HelloWorldExample { public static String getGreeting() { return "Hello from this method."; } public static void main (String [] args) { String str = getGreeting(); System.out.println(str); calls

5 Local Method Call (not distributed)
01/12/2018 Local Method Call (not distributed) Method public class HelloWorldExample { public static String getGreeting() { return "Hello from this method."; } public static void main (String [] args) { String str = getGreeting(); System.out.println(str); Caller of the Method

6 Remote Method Call (distributed)
01/12/2018 Remote Method Call (distributed) Server public class HelloWorldExample { public static String getGreeting() { return "Hello from this method."; } public static void main (String [] args) { String str = getGreeting(); System.out.println(str); Client

7 Different Programming Languages?
01/12/2018 Different Programming Languages? Java public class HelloWorldExample { public static String getGreeting() { return "Hello from this method."; } void main () { cout << getGreeting() << endl; C++

8 Client and Server have to understand each other
01/12/2018 Client and Server have to understand each other Wieviel Uhr ist es? ? Server Client

9 Client and Server agree on a common language.
01/12/2018 Client and Server agree on a common language. Quelle heure est-il? 7pm! What’s the time? Wieviel Uhr ist es? Server Client

10 01/12/2018 The client encodes the information in the “common language”, the server decodes the information. Decode Encode Quelle heure est-il? What’s the time? Wieviel Uhr ist es? Server Client

11 XML-RPC uses XML as a common language to transmit data
01/12/2018 XML-RPC uses XML as a common language to transmit data Decode Encode Java C++ Python etc. XML Java C++ Python etc. Server Client

12 That explains the XML in XML-RPC but what means RPC?
01/12/2018 That explains the XML in XML-RPC but what means RPC? RPC means “Remote Procedure Call”, that means you call a procedure (i.e. method, function) on a different machine.

13 RPC - Remote Procedure Call What is it?
01/12/2018 RPC - Remote Procedure Call What is it? RPC is a technique for constructing distributed, client-server based applications. It is based on extending the notion of conventional, or local procedure calling. As “remote” suggests, the called procedure need not to exist in the same address space as the calling procedure. The two processes may be on the same system, or they may be on different systems with a network connecting them. By using RPC architectures, programmers of distributed applications avoid the details of the interface with the network. z zz

14 Typical flow of control in RPCs
01/12/2018 Typical flow of control in RPCs The client makes a procedure call that sends a request to the server and waits. The thread is blocked from processing until either a reply is received, or it times out. When the request arrives, the server calls a dispatch routine that performs the requested service, and sends the reply to the client. After the RPC call is completed, the client program continues.

15 XML-RPC and Java: The basic idea
01/12/2018 XML-RPC and Java: The basic idea XML A Java package with specialist methods. A Java package with specialist methods. Main program (Client) Method: getGreeting() (Server) Specialist methods in the Java package org.apache.xmlrpc link the local code to the remote code.

16 01/12/2018

17 01/12/2018 What is XML-RPC? It's a spec and a set of implementations that allow software running on disparate operating systems, running in different environments to make procedure calls over the Internet It's remote procedure calling using HTTP as the transport and XML as the encoding. XML- RPC is designed to be as simple as possible, while allowing complex data structures to be transmitted, processed and returned.

18 01/12/2018 The specification, < 1800 words, is lightweight and easy to learn. Contains many examples. It's a spec and a set of implementations that allow software running on disparate operating systems, running in different environments to make procedure calls over the Internet It's remote procedure calling using HTTP as the transport and XML as the encoding. XML- RPC is designed to be as simple as possible, while allowing complex data structures to be transmitted, processed and returned. 01/12/ :12:36

19 Languages include: C/C++, Java, Perl, Python, Frontier, Lisp, PHP, Microsoft .NET, Rebol, Real Basic, Tcl, Delphi, WebObjects and Zope 01/12/2018 It's a spec and a set of implementations that allow software running on disparate operating systems, running in different environments to make procedure calls over the Internet It's remote procedure calling using HTTP as the transport and XML as the encoding. XML- RPC is designed to be as simple as possible, while allowing complex data structures to be transmitted, processed and returned. 01/12/ :12:36

20 Uses existing protocols (HTTP) and a well established framework (XML).
01/12/2018 Uses existing protocols (HTTP) and a well established framework (XML). It's a spec and a set of implementations that allow software running on disparate operating systems, running in different environments to make procedure calls over the Internet It's remote procedure calling using HTTP as the transport and XML as the encoding. XML- RPC is designed to be as simple as possible, while allowing complex data structures to be transmitted, processed and returned. 01/12/ :12:36

21 01/12/2018 The following data structures are supported: integer, boolean, string, double, date & time, base64 binaries, structs, arrays. It's a spec and a set of implementations that allow software running on disparate operating systems, running in different environments to make procedure calls over the Internet It's remote procedure calling using HTTP as the transport and XML as the encoding. XML- RPC is designed to be as simple as possible, while allowing complex data structures to be transmitted, processed and returned. 01/12/ :12:36

22 1. Writing Server and Client
01/12/2018 1. Writing Server and Client 2. Identify 3. Communicate 1. Write Client Client kdfjshkdsahfkdashfkajshfkdsjhkjsahfkdshfkhasdfkashfkdjsahfkshdfkhsafkjshfkdsfhakjdhfksjdhfakhsfkjsdfkdasjfkdasjksdajfkdsafhksajhkdjfhkasjkdsahksdjfksakdjsfksakshfdkjfdkdsfh Client Server kdfjshkdsahfkdashfkajshfkdsjhkjsahfkdshfkhasdfkashfkdjsahfkshdfkhsafkjshfkdsfhakjdhfksjdhfakhsfkjsdfkdasjfkdasjksdajfkdsafhksajhk assfksakshfdkjf Server Server

23 Example: An XML-RPC client/server application in Java.
01/12/2018 Example: An XML-RPC client/server application in Java. The Java package org.apache.xmlrpc provides classes to implement an XML-RPC client and an XML-RPC server. The package can be found at A copy of the package is under the name cis69mc.jar on .

24 A Java “Hello World” Server
01/12/2018 A Java “Hello World” Server import org.apache.xmlrpc.*; public class HelloWorldServer { public String getGreeting() { return "Hello from far away."; } public static void main (String [] args) { try { WebServer server = new WebServer(80); server.addHandler("hello", new HelloWorldServer()); server.start(); catch (Exception ex) { System.err.println("There is a problem:" + ex);

25 A Java “Hello World” Server
01/12/2018 A Java “Hello World” Server import org.apache.xmlrpc.*; public class HelloWorldServer { public String getGreeting() { return "Hello from far away."; } public static void main (String [] args) { try { WebServer server = new WebServer(80); server.addHandler("hello", new HelloWorldServer()); server.start(); catch (Exception ex) { System.err.println("There is a problem:" + ex); The package org.apache.xmlrpc contains the class WebServer for a XML-RPC Server implementation 01/12/ :12:36

26 A Java “Hello World” Server
01/12/2018 A Java “Hello World” Server import org.apache.xmlrpc.*; public class HelloWorldServer { public String getGreeting() { return "Hello from far away."; } public static void main (String [] args) { try { WebServer server = new WebServer(80); server.addHandler("hello", new HelloWorldServer()); server.start(); catch (Exception ex) { System.err.println("There is a problem:" + ex); The procedure that is called remotely is implemented as a public method in a class. An instance of this class is then associated with a handler that is accessible by the client.

27 A Java “Hello World” Server
01/12/2018 A Java “Hello World” Server import org.apache.xmlrpc.*; public class HelloWorldServer { public String getGreeting() { return "Hello from far away."; } public static void main (String [] args) { try { WebServer server = new WebServer(80); server.addHandler("hello", new HelloWorldServer()); server.start(); catch (Exception ex) { System.err.println("There is a problem:" + ex); The server is initialised by the port number (here: 80). The server starts to listen at port 80.

28 A Java “Hello World” Server
01/12/2018 import org.apache.xmlrpc.*; public class HelloWorldServer { public String getGreeting() { return "Hello from far away."; } public static void main (String [] args) { try { WebServer server = new WebServer(80); server.addHandler("hello", new HelloWorldServer()); server.start(); catch (Exception ex) { System.err.println("There is a problem:" + ex); When problems occur (ie. a different process already listening on port 80) an Exception is thrown and has to be caught.

29 01/12/2018 About Port 80 An advantage of using port 80 is that it is usually not blocked by firewalls. Port 80 is the default port used for the World Wide Web. Using port 80 justifies the word “Web” for this kind of Service: Web Service. Note that you cannot have two programs using the same port on the same computer. That means, for instance, that you cannot run two XML-RPC server at the same time (however you may use different ports, e.g. 81 or 8080)

30 A Java XML-RPC Client for the “HelloWorld” Web Service
01/12/2018 A Java XML-RPC Client for the “HelloWorld” Web Service import org.apache.xmlrpc.*; import java.util.Vector; public class HelloWorldClient { public static void main (String [] args) { try { XmlRpcClient server = new XmlRpcClient(" Vector params = new Vector(); Object result = server.execute("hello.getGreeting", params); System.out.println("Result from Server: "+ result.toString()); } catch (Exception ex) { System.err.println("HelloClient: " + ex); } 01/12/ :12:36

31 A Java XML-RPC Client for the “HelloWorld” Service
01/12/2018 A Java XML-RPC Client for the “HelloWorld” Service import org.apache.xmlrpc.*; import java.util.Vector; public class HelloWorldClient { public static void main (String [] args) { try { XmlRpcClient server = new XmlRpcClient(" Vector params = new Vector(); Object result = server.execute("hello.getGreeting", params); System.out.println("Result from Server: "+ result.toString()); } catch (Exception ex) { System.err.println("HelloClient: " + ex); The Java package org.apache.xmlrpc contains classes for XML- RPC Java clients and XML-RPC server. ie. XmlRpcClient. The package java.util is necessary for the Vector class.

32 A Java XML-RPC Client for the “HelloWorld” Server
01/12/2018 A Java XML-RPC Client for the “HelloWorld” Server import org.apache.xmlrpc.*; import java.util.Vector; public class HelloWorldClient { public static void main (String [] args) { try { XmlRpcClient server = new XmlRpcClient(" Vector params = new Vector(); Object result = server.execute("hello.getGreeting", params); System.out.println("Result from Server: "+ result.toString()); } catch (Exception ex) { System.err.println("HelloClient: " + ex); This line sends the request to the server. The procedure getGreeting() is called on the server as if it were a local procedure. The return value of a procedure call is always an Object. “hello” denotes a handler that is defined in the server.

33 A Java XML-RPC Client for the “HelloWorld” Server
01/12/2018 A Java XML-RPC Client for the “HelloWorld” Server import org.apache.xmlrpc.*; import java.util.Vector; public class HelloWorldClient { public static void main (String [] args) { try { XmlRpcClient server = new XmlRpcClient(" Vector params = new Vector(); Object result = server.execute("hello.getGreeting", params); System.out.println("Result from Server: "+ result.toString()); } catch (Exception ex) { System.err.println("HelloClient: " + ex); The parameters of the procedure call are always collected in a Vector. In this example the procedure has no parameters.

34 A Java XML-RPC Client for the “HelloWorld” Server
01/12/2018 A Java XML-RPC Client for the “HelloWorld” Server import org.apache.xmlrpc.*; import java.util.Vector; public class HelloWorldClient { public static void main (String [] args) { try { XmlRpcClient server = new XmlRpcClient(" Vector params = new Vector(); Object result = server.execute("hello.getGreeting", params); System.out.println("Result from Server: "+ result.toString()); } catch (Exception ex) { System.err.println("HelloClient: " + ex);

35 A Java XML-RPC Client for the “HelloWorld” Server
01/12/2018 A Java XML-RPC Client for the “HelloWorld” Server import org.apache.xmlrpc.*; import java.util.Vector; public class HelloWorldClient { public static void main (String [] args) { try { XmlRpcClient server = new XmlRpcClient(" Vector params = new Vector(); Object result = server.execute("hello.getGreeting", params); System.out.println("Result from Server: "+ result.toString()); } catch (Exception ex) { System.err.println("HelloClient: " + ex); The XmlRpcClient class is constructed by specifying the “web address” of the server machine followed by /RPC2. E.g. localhost - means the local machine. An IP number, e.g A name, e.g. cis69.dyndns.org All of the above, followed by a port number, e.g. cis69.dyndns.org:8080. The default port is 80.

36 2. Identification of the Remote Service
01/12/2018 2. Identification of the Remote Service 2. Identify 3. Communicate 1. Write Client Client kdfjshkdsahfkdashfkajshfkdsjhkjsahfkdshfkhasdfkashfkdjsahfkshdfkhsafkjshfkdsfhakjdhfksjdhfakhsfkjsdfkdasjfkdasjksdajfkdsafhksajhkdjfhkasjkdsahksdjfksakdjsfksakshfdkjfdkdsfh Client Server kdfjshkdsahfkdashfkajshfkdsjhkjsahfkdshfkhasdfkashfkdjsahfkshdfkhsafkjshfkdsfhakjdhfksjdhfakhsfkjsdfkdasjfkdasjksdajfkdsafhksajhk assfksakshfdkjf Server Server

37 Localhost and remote hosts
01/12/2018 Localhost and remote hosts In our example Server and Client are running on the same Computer. Hence we can use the address If you are using the program on two machines that are connected to the Internet, use the IP address of the Server machine to make the connection (for instance You can find the IP address of a computer with the program ipconfig. If the Server machine is registered with a name (as ie. ) You can use the name instead of the IP address (ie. The suffix “/RPC2” is used by some Web Servers to discriminate between XML-RPC calls and other incoming calls (for instance requests for HTML pages)

38 01/12/2018 ? What do we need to tell the client so that it can connect to the Server? For a remote procedure call via the XML-RPC protocol we need the following information on the client side: The location of the remote service. The name of the remote procedure. The parameters of the remote procedure. The return type of the remote procedure.

39 3. Communication between Client and Server
01/12/2018 3. Communication between Client and Server 2. Identify 3. Communicate 1. Write Client Client kdfjshkdsahfkdashfkajshfkdsjhkjsahfkdshfkhasdfkashfkdjsahfkshdfkhsafkjshfkdsfhakjdhfksjdhfakhsfkjsdfkdasjfkdasjksdajfkdsafhksajhkdjfhkasjkdsahksdjfksakdjsfksakshfdkjfdkdsfh Client Server kdfjshkdsahfkdashfkajshfkdsjhkjsahfkdshfkhasdfkashfkdjsahfkshdfkhsafkjshfkdsfhakjdhfksjdhfakhsfkjsdfkdasjfkdasjksdajfkdsafhksajhk assfksakshfdkjf Server Server

40 Client Server Request from Client to Server
01/12/2018 Client Server <?xml version="1.0" encoding="ISO "?> <methodCall> <methodName>hello.getGreeting</methodName> <params></params> </methodCall> The name of the method that is to be called on the Server. (empty) list of parameters. Request from Client to Server

41 Client Server <?xml version="1.0" encoding="ISO-8859-1"?>
01/12/2018 Client Server <?xml version="1.0" encoding="ISO "?> <methodResponse> <params> <param> <value>Hello from far away.</value> </param> </params> </methodResponse> The String that is returned to the Client from the Server. Response from the Server to the Client

42 Simple Object Access Protocol
01/12/2018 Simple Object Access Protocol SOAP is another protocol for Client/Server applications. The general principle is similar as XML-RPC by using XML as common language. Also labelled as “lightweight”, but the specification is > words.

43 01/12/2018 SOAP and XML-RPC Wikipedia (2005): “[XML-RPC] was first created by Dave Winer of UserLand Software in with Microsoft. However Microsoft considered it too simple, and started adding functionality. After several rounds of this, the standard was no longer so simple, and became what is now SOAP.” So, XML-RPC is An excellent starting point for understanding the principles behind SOAP. More lightweight and easier to learn.

44 01/12/2018 Summary In our example, Client and Server have been written in the XML-RPC architecture using the programming language Java on both the Client and Server side. The remote service is identified via the IP number. The communication protocol is based on XML. This is a very simple form of a web service ie. predecessor of SOAP.


Download ppt "CIS Distributed and Parallel Architectures"

Similar presentations


Ads by Google