SlideShare a Scribd company logo
Slides for Chapter 4:
Interprocess Communication




From Coulouris, Dollimore, Kindberg and Blair
Distributed Systems:
          Concepts and Design
Edition 5, © Addison-Wesley 2012
Figure 4.1
Middleware layers




                    Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5
                                                                 © Pearson Education 2012
Application Program Interface


The application program interface to UDP provides a message
  passing abstraction. This enables a sending process to transmit a
  single message to a receiving process.
The application program interface to TCP provides the abstraction of
  a two-way stream between pairs of processes. The information
  communicated consists of a stream of data items with no
  message boundaries.




                                                             3
The characteristics of interprocess communication


   Synchronous and asynchronous communication
   Message destinations (Internet address, local port)
   Reliability
   Ordering




                                                          4
Figure 4.2
Sockets and ports




                                                                          agreed port
          socket                             any port                                                                           socket

                                                               message
            client                                                                                                              server
                                                             other ports

Internet address = 138.37.94.248                                                                 Internet address = 138.37.88.249




                     Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5
                                                                  © Pearson Education 2012
Java API for Internet addresses


 As the IP packets underlying UDP and TCP are sent to
  Internet addresses, Java provides a class, InetAddress, that
  represents Internet addresses.
 Users of this class refer to computers by Domain Name
  System (DNS) hostnames.
 For example, instances of InetAddress that contain Internet
  addresses can be created by calling a static method of
  InetAddress, giving a DNS hostname as the argument.
 The method uses the DNS to get the corresponding Internet
  address.
 InetAddress aComputer =InetAddress.getByName("bruno.dcs.qmul.ac.uk");
 This method can throw an UnknownHostException.
                                                                          6
Figure 4.3
UDP client sends a message to the server and gets a reply

import java.net.*;
import java.io.*;
public class UDPClient{
   public static void main(String args[]){
            // args give message contents and server hostname
            DatagramSocket aSocket = null;
              try {
                         aSocket = new DatagramSocket();
                         byte [] m = args[0].getBytes();
                         InetAddress aHost = InetAddress.getByName(args[1]);
                         int serverPort = 6789;
//Datagram packet array of bytes containing message length of message Internet address port number
                         DatagramPacket request = new DatagramPacket(m, m.length(), aHost, serverPort);
                         aSocket.send(request);
                         byte[] buffer = new byte[1000];
                         DatagramPacket reply = new DatagramPacket(buffer, buffer.length);
                         aSocket.receive(reply);
                         System.out.println("Reply: " + new String(reply.getData()));
              }catch (SocketException e){System.out.println("Socket: " + e.getMessage());
              }catch (IOException e){System.out.println("IO: " + e.getMessage());}
            }finally {if(aSocket != null) aSocket.close();}
  }                            Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5
                                                                            © Pearson Education 2012
}
Figure 4.4
UDP server repeatedly receives a request and sends it back to the client


  import java.net.*;
  import java.io.*;
  public class UDPServer{
             public static void main(String args[]){
             DatagramSocket aSocket = null;
                try{
                          aSocket = new DatagramSocket(6789);
                          byte[] buffer = new byte[1000];
                          while(true){
                             DatagramPacket request = new DatagramPacket(buffer, buffer.length);
                            aSocket.receive(request);
                            DatagramPacket reply = new DatagramPacket(request.getData(),
                                     request.getLength(), request.getAddress(), request.getPort());
                            aSocket.send(reply);
                          }
                }catch (SocketException e){System.out.println("Socket: " + e.getMessage());
               }catch (IOException e) {System.out.println("IO: " + e.getMessage());}
             }finally {if(aSocket != null) aSocket.close();}
    }
  }
                         Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5
                                                                      © Pearson Education 2012
Figure 4.5
TCP client makes connection to server, sends request and receives reply

    import java.net.*;
    import java.io.*;
    public class TCPClient {
                 public static void main (String args[]) {
                 // arguments supply message and hostname of destination
                 Socket s = null;
                    try{
                                int serverPort = 7896;
                                s = new Socket(args[1], serverPort);
                                DataInputStream in = new DataInputStream( s.getInputStream());
                                DataOutputStream out =
                                             new DataOutputStream( s.getOutputStream());
                                out.writeUTF(args[0]);                // UTF is a string encoding see Sn 4.3
                                String data = in.readUTF();
                                System.out.println("Received: "+ data) ;
                    }catch (UnknownHostException e){
                                             System.out.println("Sock:"+e.getMessage());
                    }catch (EOFException e){System.out.println("EOF:"+e.getMessage());
                    }catch (IOException e){System.out.println("IO:"+e.getMessage());}
                 }finally {if(s!=null) try {s.close();}catch (IOException e){System.out.println("close:"+e.getMessage());}}
                 }
    }


                           Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5
                                                                        © Pearson Education 2012
Figure 4.6
TCP server makes a connection for each client and then echoes the client’s request


       import java.net.*;
       import java.io.*;
       public class TCPServer {
         public static void main (String args[]) {
                  try{
                             int serverPort = 7896;
                             ServerSocket listenSocket = new ServerSocket(serverPort);
                             while(true) {
                                         Socket clientSocket = listenSocket.accept();
                                         Connection c = new Connection(clientSocket);
                             }
                  } catch(IOException e) {System.out.println("Listen :"+e.getMessage());}
         }
       }

       // this figure continues on the next slide




                        Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5
                                                                     © Pearson Education 2012
Figure 4.6 continued

     class Connection extends Thread {
               DataInputStream in;
               DataOutputStream out;
               Socket clientSocket;
               public Connection (Socket aClientSocket) {
                 try {
                           clientSocket = aClientSocket;
                           in = new DataInputStream( clientSocket.getInputStream());
                           out =new DataOutputStream( clientSocket.getOutputStream());
                           this.start();
                  } catch(IOException e) {System.out.println("Connection:"+e.getMessage());}
               }
               public void run(){
                 try {                                        // an echo server
                           String data = in.readUTF();
                           out.writeUTF(data);
                 } catch(EOFException e) {System.out.println("EOF:"+e.getMessage());
                 } catch(IOException e) {System.out.println("IO:"+e.getMessage());}
                 } finally{ try {clientSocket.close();}catch (IOException e){/*close failed*/}}
               }
     }
                       Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5
                                                                    © Pearson Education 2012
Marshalling and Unmarshalling


 Marshalling is the process of taking a collection of data items
  and assembling them into a form suitable for transmission in
  a message.
 Unmarshalling is the process of disassembling them on
  arrival to produce an equivalent collection of data items at the
  destination.
 Thus marshalling consists of the translation of structured data
  items and primitive values into an external data
  representation.
 Similarly, unmarshalling consists of the generation of primitive
  values from their external data representation and the
  rebuilding of the data structures.
                                                             12
Common Object Request Broker Architecture (CORBA)


 standard for software interoperability (set of common, object-
  oriented interfaces that can communicate on various
  platforms) .
 CORBA is most popular in communications Middleware using
  an Object Request Broker ORB.
 CORBA evolved out of TCP/IP.




                                                           13
Figure 4.7
CORBA’s Common Data Representation (CDR) for constructed types




                 Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5
                                                              © Pearson Education 2012
Figure 4.8
CORBA CDR message


             index in                                                                                 notes
             sequence of bytes                                    4 bytes                             on representation
             0–3                                           5                                          length of string
             4–7                                           "Smit"                                    ‘Smith’
             8–11                                          "h___"
             12–15                                           6                                       length of string
             16–19                                         "Lond"                                    ‘London’
             20-23                                         "on__"
             24–27                                         1984                                       unsigned long

     The flattened form represents a Person struct with value: {‘Smith’, ‘London’, 1984}




                   Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5
                                                                © Pearson Education 2012
Marshalling in CORBA


 Marshalling operations can be generated automatically from
  the specification of the types of data items to be transmitted in
  a message.




                                                              16
Figure 4.9
Indication of Java serialized form




                   Serialized values                                                                                           Explanation
 Person        8-byte version number                                      h0                                         class name, version number

            int year            java.lang.String java.lang.String number, type and name of
 3                              name:            place:            instance variables
 1984       5 Smith             6 London                                  h1                                         values of instance variables

The true serialized form contains additional type markers; h0 and h1 are handles




                       Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5
                                                                    © Pearson Education 2012
Figure 4.10 XML definition of the Person structure




   <person id="123456789">
            <name>Smith</name>
            <place>London</place>
            <year>1984</year>
            <!-- a comment -->
   </person >


                   Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5
                                                                © Pearson Education 2012
Figure 4.11 Illustration of the use of a namespace in the Person structure



<person pers:id="123456789" xmlns:pers = "http://www.cdk5.net/person">
       <pers:name> Smith </pers:name>
       <pers:place> London </pers:place >
       <pers:year> 1984 </pers:year>
</person>




                    Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5
                                                                 © Pearson Education 2012
Figure 4.12 An XML schema for the Person structure



<xsd:schema xmlns:xsd = URL of XML schema definitions           >
       <xsd:element name= "person" type ="personType" />
              <xsd:complexType name="personType">
                     <xsd:sequence>
                            <xsd:element name = "name" type="xs:string"
                            <xsd:element name = "place" type="xs:string"
                            <xsd:element name = "year" type="xs:positive
                     </xsd:sequence>
                     <xsd:attribute name= "id" type = "xs:positiveInteger"
              </xsd:complexType>
</xsd:schema>

                  Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5
                                                               © Pearson Education 2012
Figure 4.13
 Representation of a remote object reference


 When a client invokes a method in a remote object, an invocation
  message is sent to the server process that hosts the remote
  object.
 This message needs to specify which particular object is to have
  its method invoked. A remote object reference is an identifier for
  a remote object that is valid throughout a distributed system.
 A remote object reference is passed in the invocation message
  to specify which object is to be invoked.

       32 bits             32 bits                               32 bits                                  32 bits
                                                                                                                                         interface of
   Internet address   port number                          time                                 object number                            remote object

                      Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5
                                                                   © Pearson Education 2012
Multicast Communication


 A multicast operation is an operation that sends a single
  message from one process to each of the members of a group of
  processes, usually in such a way that the membership of the
  group is transparent to the sender.

 Multicast messages provide a useful infrastructure     for
  constructing     distributed systems with the   following
  characteristics:
       Fault tolerance based on replicated services
       Discovering services in spontaneous networking
       Better performance through replicated data
       Propagation of event notifications

                    Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5
                                                                 © Pearson Education 2012
IP multicast – An implementation of multicast communication


 IP multicast is built on top of the Internet Protocol (IP). Note
  that IP packets are addressed to computers – ports belong to
  the TCP and UDP levels.

 IP multicast allows the sender to transmit a single IP packet to
  a set of computers that form a multicast group.

 The sender is unaware of the identities of the individual
  recipients and of the size of the group. A multicast group is
  specified by a Class D Internet address – that is, an address
  whose first 4 bits are 1110 in IPv4. (remember that we need
  Multicast routers and Multicast address allocation).
                                                              23
Figure 4.14
Multicast peer joins a group and sends and receives datagrams


import java.net.*;
import java.io.*;
public class MulticastPeer{
          public static void main(String args[]){
           // args give message contents & destination multicast group (e.g. "228.5.6.7")
          MulticastSocket s =null;
           try {
                     InetAddress group = InetAddress.getByName(args[1]);
                     s = new MulticastSocket(6789);
                     s.joinGroup(group);
                     byte [] m = args[0].getBytes();
                     DatagramPacket messageOut =
                               new DatagramPacket(m, m.length, group, 6789);
                     s.send(messageOut);


          // this figure continued on the next slide

                       Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5
                                                                    © Pearson Education 2012
Figure 4.14
continued


            // get messages from others in group
                    byte[] buffer = new byte[1000];
                    for(int i=0; i< 3; i++) {
                       DatagramPacket messageIn =
                               new DatagramPacket(buffer, buffer.length);
                       s.receive(messageIn);
                       System.out.println("Received:" + new String(messageIn.getData()));
                    }
                    s.leaveGroup(group);
            }catch (SocketException e){System.out.println("Socket: " + e.getMessage());
           }catch (IOException e){System.out.println("IO: " + e.getMessage());}
         }finally {if(s != null) s.close();}
     }
 }




                     Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5
                                                                  © Pearson Education 2012
Network virtualization


 Network virtualization is concerned with the construction of
  many different virtual networks over an existing network such
  as the Internet.
 Each virtual network can be designed to support a particular
  distributed application.
 For example, one virtual network might support multimedia
  streaming, as in BBC iPlayer, and coexist with another that
  supports a multiplayer online game, both running over the
  same underlying network.




                                                           26
Overlay networks


 An overlay network is a virtual network consisting of nodes
  and virtual links, which sits on top of an underlying network
  (such as an IP network) and offers something that is not
  otherwise provided:
    a service that is tailored towards the needs of a class of application or
     a particular higher-level service – for example, multimedia content
     distribution;
    more efficient operation in a given networked environment – for
     example routing in an ad hoc network;
    an additional feature – for example, multicast or secure
     communication.




                                                                        27
Figure 4.15
Types of overlay




table continues on the next slide
                     Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5
                                                                  © Pearson Education 2012
                                                                                                                                        28
Figure 4.15 (continued)
Types of overlay




                   Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5
                                                                © Pearson Education 2012
                                                                                                                                      29
Figure 4.16
  Skype overlay architecture


 Skype is a peer-to-peer application offering
  Voice over IP (VoIP).
 It also includes instant messaging, video
  conferencing and interfaces to the standard
  telephony service through SkypeIn and
  SkypeOut. The software was developed by
  Kazaa in 2003 and hence shares many of
  the characteristics of the Kazaa peer-to-
  peer file-sharing application.
 It is widely deployed, with an estimated 370
  million users as of the start of 2009.
 Skype is an excellent case study of the use
  of overlay networks in real-world (and large-
  scale) systems.

                     Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5
                                                                  © Pearson Education 2012
                                                                                                                                        30
Figure 4.17
Point-to-point communication in Message Passing Interface (MPI)




                  Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5
                                                               © Pearson Education 2012
                                                                                                                                     31
Figure 4.18
Selected send operations in MPI




                  Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5
                                                               © Pearson Education 2012
                                                                                                                                     32

More Related Content

PPT
Chapter 5 slides
DOC
Naming in Distributed System
PPT
Unit 5 Application Layer
PDF
Array Processor
PPT
PPTX
Server system architecture
PPTX
RPC: Remote procedure call
PPT
Ethernet protocol
Chapter 5 slides
Naming in Distributed System
Unit 5 Application Layer
Array Processor
Server system architecture
RPC: Remote procedure call
Ethernet protocol

What's hot (20)

PPTX
UNIT 3: Data Warehousing and Data Mining
PPTX
Lan architecture
PPTX
PPTX
Data link layer
PPT
Socket System Calls
PDF
Self assessment true-false Quiz: Chapter 1 - Computer Networking a top-down A...
PDF
CS8591 Computer Networks - Unit I
PPTX
Transport layer
PPTX
Reference models in Networks: OSI & TCP/IP
PPTX
05 Clustering in Data Mining
PPTX
Presentation Routing algorithm
DOC
Unit 2 in daa
PPT
HadoooIO.ppt
PPTX
Connecting devices
PDF
Distributed Systems Naming
PPTX
Normal forms
PPT
Network layer tanenbaum
PPTX
ARP,RARP,DHCP,ICMP NETWORKING PROTOCOLS INTERNET
PPTX
UNIT 3: Data Warehousing and Data Mining
Lan architecture
Data link layer
Socket System Calls
Self assessment true-false Quiz: Chapter 1 - Computer Networking a top-down A...
CS8591 Computer Networks - Unit I
Transport layer
Reference models in Networks: OSI & TCP/IP
05 Clustering in Data Mining
Presentation Routing algorithm
Unit 2 in daa
HadoooIO.ppt
Connecting devices
Distributed Systems Naming
Normal forms
Network layer tanenbaum
ARP,RARP,DHCP,ICMP NETWORKING PROTOCOLS INTERNET
Ad

Viewers also liked (20)

PPT
Chapter 6 slides
PPT
Chapter 7 slides
PPT
Chapter 2 system models
PPT
Chapter 3 slides
PPT
Stij5014 distributed systems
PPT
Chapter 3 a
PPT
Chapter 2 slides
PPT
Chapter 1 slides
PPT
Distributed Systems
PPT
Chapter 2 slides
PPT
Chapter 10.slides
PPT
Chapter 1 slides
PPT
Chapter 7 security
PPT
Chapter 9 slides
PPT
Ds objects and models
PPT
Data communications
PPT
Chapter 1 slides
PPT
Chapter 13
PPT
Chapter 3 slides (Distributed Systems)
Chapter 6 slides
Chapter 7 slides
Chapter 2 system models
Chapter 3 slides
Stij5014 distributed systems
Chapter 3 a
Chapter 2 slides
Chapter 1 slides
Distributed Systems
Chapter 2 slides
Chapter 10.slides
Chapter 1 slides
Chapter 7 security
Chapter 9 slides
Ds objects and models
Data communications
Chapter 1 slides
Chapter 13
Chapter 3 slides (Distributed Systems)
Ad

Similar to Chapter 4 slides (20)

PDF
DOCX
Lab manual cn-2012-13
PDF
ikh331-06-distributed-programming
PPT
Unit 2 DSDSDSDSDSDSDSDSDSDSDSDSDSDSDSDSDSDSDS.ppt
PPTX
分散式系統
PDF
CS6601 DISTRIBUTED SYSTEMS
PPTX
CHAPTER - 3 - JAVA NETWORKING.pptx
PDF
Lecture6
PPTX
Advanced Java Programming: Introduction and Overview of Java Networking 1. In...
PPT
Pemrograman Jaringan
PPTX
#2 (UDP)
PPT
Socket Programming
PDF
nw-lab_dns-server.pdf
PPTX
Advance Java-Network Programming
PPT
Unit 8 Java
PPTX
EN-04 (1).pptx
PPT
Socket Programming - nitish nagar
PPT
Network
PPT
Socket Programming
PPT
Sockets
Lab manual cn-2012-13
ikh331-06-distributed-programming
Unit 2 DSDSDSDSDSDSDSDSDSDSDSDSDSDSDSDSDSDSDS.ppt
分散式系統
CS6601 DISTRIBUTED SYSTEMS
CHAPTER - 3 - JAVA NETWORKING.pptx
Lecture6
Advanced Java Programming: Introduction and Overview of Java Networking 1. In...
Pemrograman Jaringan
#2 (UDP)
Socket Programming
nw-lab_dns-server.pdf
Advance Java-Network Programming
Unit 8 Java
EN-04 (1).pptx
Socket Programming - nitish nagar
Network
Socket Programming
Sockets

Chapter 4 slides

  • 1. Slides for Chapter 4: Interprocess Communication From Coulouris, Dollimore, Kindberg and Blair Distributed Systems: Concepts and Design Edition 5, © Addison-Wesley 2012
  • 2. Figure 4.1 Middleware layers Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5 © Pearson Education 2012
  • 3. Application Program Interface The application program interface to UDP provides a message passing abstraction. This enables a sending process to transmit a single message to a receiving process. The application program interface to TCP provides the abstraction of a two-way stream between pairs of processes. The information communicated consists of a stream of data items with no message boundaries. 3
  • 4. The characteristics of interprocess communication  Synchronous and asynchronous communication  Message destinations (Internet address, local port)  Reliability  Ordering 4
  • 5. Figure 4.2 Sockets and ports agreed port socket any port socket message client server other ports Internet address = 138.37.94.248 Internet address = 138.37.88.249 Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5 © Pearson Education 2012
  • 6. Java API for Internet addresses  As the IP packets underlying UDP and TCP are sent to Internet addresses, Java provides a class, InetAddress, that represents Internet addresses.  Users of this class refer to computers by Domain Name System (DNS) hostnames.  For example, instances of InetAddress that contain Internet addresses can be created by calling a static method of InetAddress, giving a DNS hostname as the argument.  The method uses the DNS to get the corresponding Internet address.  InetAddress aComputer =InetAddress.getByName("bruno.dcs.qmul.ac.uk");  This method can throw an UnknownHostException. 6
  • 7. Figure 4.3 UDP client sends a message to the server and gets a reply import java.net.*; import java.io.*; public class UDPClient{ public static void main(String args[]){ // args give message contents and server hostname DatagramSocket aSocket = null; try { aSocket = new DatagramSocket(); byte [] m = args[0].getBytes(); InetAddress aHost = InetAddress.getByName(args[1]); int serverPort = 6789; //Datagram packet array of bytes containing message length of message Internet address port number DatagramPacket request = new DatagramPacket(m, m.length(), aHost, serverPort); aSocket.send(request); byte[] buffer = new byte[1000]; DatagramPacket reply = new DatagramPacket(buffer, buffer.length); aSocket.receive(reply); System.out.println("Reply: " + new String(reply.getData())); }catch (SocketException e){System.out.println("Socket: " + e.getMessage()); }catch (IOException e){System.out.println("IO: " + e.getMessage());} }finally {if(aSocket != null) aSocket.close();} } Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5 © Pearson Education 2012 }
  • 8. Figure 4.4 UDP server repeatedly receives a request and sends it back to the client import java.net.*; import java.io.*; public class UDPServer{ public static void main(String args[]){ DatagramSocket aSocket = null; try{ aSocket = new DatagramSocket(6789); byte[] buffer = new byte[1000]; while(true){ DatagramPacket request = new DatagramPacket(buffer, buffer.length); aSocket.receive(request); DatagramPacket reply = new DatagramPacket(request.getData(), request.getLength(), request.getAddress(), request.getPort()); aSocket.send(reply); } }catch (SocketException e){System.out.println("Socket: " + e.getMessage()); }catch (IOException e) {System.out.println("IO: " + e.getMessage());} }finally {if(aSocket != null) aSocket.close();} } } Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5 © Pearson Education 2012
  • 9. Figure 4.5 TCP client makes connection to server, sends request and receives reply import java.net.*; import java.io.*; public class TCPClient { public static void main (String args[]) { // arguments supply message and hostname of destination Socket s = null; try{ int serverPort = 7896; s = new Socket(args[1], serverPort); DataInputStream in = new DataInputStream( s.getInputStream()); DataOutputStream out = new DataOutputStream( s.getOutputStream()); out.writeUTF(args[0]); // UTF is a string encoding see Sn 4.3 String data = in.readUTF(); System.out.println("Received: "+ data) ; }catch (UnknownHostException e){ System.out.println("Sock:"+e.getMessage()); }catch (EOFException e){System.out.println("EOF:"+e.getMessage()); }catch (IOException e){System.out.println("IO:"+e.getMessage());} }finally {if(s!=null) try {s.close();}catch (IOException e){System.out.println("close:"+e.getMessage());}} } } Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5 © Pearson Education 2012
  • 10. Figure 4.6 TCP server makes a connection for each client and then echoes the client’s request import java.net.*; import java.io.*; public class TCPServer { public static void main (String args[]) { try{ int serverPort = 7896; ServerSocket listenSocket = new ServerSocket(serverPort); while(true) { Socket clientSocket = listenSocket.accept(); Connection c = new Connection(clientSocket); } } catch(IOException e) {System.out.println("Listen :"+e.getMessage());} } } // this figure continues on the next slide Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5 © Pearson Education 2012
  • 11. Figure 4.6 continued class Connection extends Thread { DataInputStream in; DataOutputStream out; Socket clientSocket; public Connection (Socket aClientSocket) { try { clientSocket = aClientSocket; in = new DataInputStream( clientSocket.getInputStream()); out =new DataOutputStream( clientSocket.getOutputStream()); this.start(); } catch(IOException e) {System.out.println("Connection:"+e.getMessage());} } public void run(){ try { // an echo server String data = in.readUTF(); out.writeUTF(data); } catch(EOFException e) {System.out.println("EOF:"+e.getMessage()); } catch(IOException e) {System.out.println("IO:"+e.getMessage());} } finally{ try {clientSocket.close();}catch (IOException e){/*close failed*/}} } } Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5 © Pearson Education 2012
  • 12. Marshalling and Unmarshalling  Marshalling is the process of taking a collection of data items and assembling them into a form suitable for transmission in a message.  Unmarshalling is the process of disassembling them on arrival to produce an equivalent collection of data items at the destination.  Thus marshalling consists of the translation of structured data items and primitive values into an external data representation.  Similarly, unmarshalling consists of the generation of primitive values from their external data representation and the rebuilding of the data structures. 12
  • 13. Common Object Request Broker Architecture (CORBA)  standard for software interoperability (set of common, object- oriented interfaces that can communicate on various platforms) .  CORBA is most popular in communications Middleware using an Object Request Broker ORB.  CORBA evolved out of TCP/IP. 13
  • 14. Figure 4.7 CORBA’s Common Data Representation (CDR) for constructed types Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5 © Pearson Education 2012
  • 15. Figure 4.8 CORBA CDR message index in notes sequence of bytes 4 bytes on representation 0–3 5 length of string 4–7 "Smit" ‘Smith’ 8–11 "h___" 12–15 6 length of string 16–19 "Lond" ‘London’ 20-23 "on__" 24–27 1984 unsigned long The flattened form represents a Person struct with value: {‘Smith’, ‘London’, 1984} Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5 © Pearson Education 2012
  • 16. Marshalling in CORBA  Marshalling operations can be generated automatically from the specification of the types of data items to be transmitted in a message. 16
  • 17. Figure 4.9 Indication of Java serialized form Serialized values Explanation Person 8-byte version number h0 class name, version number int year java.lang.String java.lang.String number, type and name of 3 name: place: instance variables 1984 5 Smith 6 London h1 values of instance variables The true serialized form contains additional type markers; h0 and h1 are handles Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5 © Pearson Education 2012
  • 18. Figure 4.10 XML definition of the Person structure <person id="123456789"> <name>Smith</name> <place>London</place> <year>1984</year> <!-- a comment --> </person > Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5 © Pearson Education 2012
  • 19. Figure 4.11 Illustration of the use of a namespace in the Person structure <person pers:id="123456789" xmlns:pers = "http://www.cdk5.net/person"> <pers:name> Smith </pers:name> <pers:place> London </pers:place > <pers:year> 1984 </pers:year> </person> Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5 © Pearson Education 2012
  • 20. Figure 4.12 An XML schema for the Person structure <xsd:schema xmlns:xsd = URL of XML schema definitions > <xsd:element name= "person" type ="personType" /> <xsd:complexType name="personType"> <xsd:sequence> <xsd:element name = "name" type="xs:string" <xsd:element name = "place" type="xs:string" <xsd:element name = "year" type="xs:positive </xsd:sequence> <xsd:attribute name= "id" type = "xs:positiveInteger" </xsd:complexType> </xsd:schema> Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5 © Pearson Education 2012
  • 21. Figure 4.13 Representation of a remote object reference  When a client invokes a method in a remote object, an invocation message is sent to the server process that hosts the remote object.  This message needs to specify which particular object is to have its method invoked. A remote object reference is an identifier for a remote object that is valid throughout a distributed system.  A remote object reference is passed in the invocation message to specify which object is to be invoked. 32 bits 32 bits 32 bits 32 bits interface of Internet address port number time object number remote object Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5 © Pearson Education 2012
  • 22. Multicast Communication  A multicast operation is an operation that sends a single message from one process to each of the members of a group of processes, usually in such a way that the membership of the group is transparent to the sender.  Multicast messages provide a useful infrastructure for constructing distributed systems with the following characteristics:  Fault tolerance based on replicated services  Discovering services in spontaneous networking  Better performance through replicated data  Propagation of event notifications Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5 © Pearson Education 2012
  • 23. IP multicast – An implementation of multicast communication  IP multicast is built on top of the Internet Protocol (IP). Note that IP packets are addressed to computers – ports belong to the TCP and UDP levels.  IP multicast allows the sender to transmit a single IP packet to a set of computers that form a multicast group.  The sender is unaware of the identities of the individual recipients and of the size of the group. A multicast group is specified by a Class D Internet address – that is, an address whose first 4 bits are 1110 in IPv4. (remember that we need Multicast routers and Multicast address allocation). 23
  • 24. Figure 4.14 Multicast peer joins a group and sends and receives datagrams import java.net.*; import java.io.*; public class MulticastPeer{ public static void main(String args[]){ // args give message contents & destination multicast group (e.g. "228.5.6.7") MulticastSocket s =null; try { InetAddress group = InetAddress.getByName(args[1]); s = new MulticastSocket(6789); s.joinGroup(group); byte [] m = args[0].getBytes(); DatagramPacket messageOut = new DatagramPacket(m, m.length, group, 6789); s.send(messageOut); // this figure continued on the next slide Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5 © Pearson Education 2012
  • 25. Figure 4.14 continued // get messages from others in group byte[] buffer = new byte[1000]; for(int i=0; i< 3; i++) { DatagramPacket messageIn = new DatagramPacket(buffer, buffer.length); s.receive(messageIn); System.out.println("Received:" + new String(messageIn.getData())); } s.leaveGroup(group); }catch (SocketException e){System.out.println("Socket: " + e.getMessage()); }catch (IOException e){System.out.println("IO: " + e.getMessage());} }finally {if(s != null) s.close();} } } Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5 © Pearson Education 2012
  • 26. Network virtualization  Network virtualization is concerned with the construction of many different virtual networks over an existing network such as the Internet.  Each virtual network can be designed to support a particular distributed application.  For example, one virtual network might support multimedia streaming, as in BBC iPlayer, and coexist with another that supports a multiplayer online game, both running over the same underlying network. 26
  • 27. Overlay networks  An overlay network is a virtual network consisting of nodes and virtual links, which sits on top of an underlying network (such as an IP network) and offers something that is not otherwise provided:  a service that is tailored towards the needs of a class of application or a particular higher-level service – for example, multimedia content distribution;  more efficient operation in a given networked environment – for example routing in an ad hoc network;  an additional feature – for example, multicast or secure communication. 27
  • 28. Figure 4.15 Types of overlay table continues on the next slide Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5 © Pearson Education 2012 28
  • 29. Figure 4.15 (continued) Types of overlay Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5 © Pearson Education 2012 29
  • 30. Figure 4.16 Skype overlay architecture  Skype is a peer-to-peer application offering Voice over IP (VoIP).  It also includes instant messaging, video conferencing and interfaces to the standard telephony service through SkypeIn and SkypeOut. The software was developed by Kazaa in 2003 and hence shares many of the characteristics of the Kazaa peer-to- peer file-sharing application.  It is widely deployed, with an estimated 370 million users as of the start of 2009.  Skype is an excellent case study of the use of overlay networks in real-world (and large- scale) systems. Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5 © Pearson Education 2012 30
  • 31. Figure 4.17 Point-to-point communication in Message Passing Interface (MPI) Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5 © Pearson Education 2012 31
  • 32. Figure 4.18 Selected send operations in MPI Instructor’s Guide for Coulouris, Dollimore, Kindberg and Blair, Distributed Systems: Concepts and Design Edn. 5 © Pearson Education 2012 32