SlideShare una empresa de Scribd logo
1 de 32
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

Más contenido relacionado

La actualidad más candente

Security Patterns with the WSO2 ESB
Security Patterns with the WSO2 ESBSecurity Patterns with the WSO2 ESB
Security Patterns with the WSO2 ESBWSO2
 
Chapter 6 slides
Chapter 6 slidesChapter 6 slides
Chapter 6 slideslara_ays
 
Chapter 4 a interprocess communication
Chapter 4 a interprocess communicationChapter 4 a interprocess communication
Chapter 4 a interprocess communicationAbDul ThaYyal
 
Interprocess communication
Interprocess communicationInterprocess communication
Interprocess communicationSushil Singh
 
virtual hosting and configuration
virtual hosting and configurationvirtual hosting and configuration
virtual hosting and configurationHAMZA AHMED
 
Implementation of page table
Implementation of page tableImplementation of page table
Implementation of page tableguestff64339
 
Interprocess communication (IPC) IN O.S
Interprocess communication (IPC) IN O.SInterprocess communication (IPC) IN O.S
Interprocess communication (IPC) IN O.SHussain Ala'a Alkabi
 
An introduction to system-oriented evaluation in Information Retrieval
An introduction to system-oriented evaluation in Information RetrievalAn introduction to system-oriented evaluation in Information Retrieval
An introduction to system-oriented evaluation in Information RetrievalMounia Lalmas-Roelleke
 
CS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSCS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSKathirvel Ayyaswamy
 

La actualidad más candente (20)

Security Patterns with the WSO2 ESB
Security Patterns with the WSO2 ESBSecurity Patterns with the WSO2 ESB
Security Patterns with the WSO2 ESB
 
Chapter 6 slides
Chapter 6 slidesChapter 6 slides
Chapter 6 slides
 
Naming in Distributed System
Naming in Distributed SystemNaming in Distributed System
Naming in Distributed System
 
Firewalls
FirewallsFirewalls
Firewalls
 
Chapter 4 a interprocess communication
Chapter 4 a interprocess communicationChapter 4 a interprocess communication
Chapter 4 a interprocess communication
 
IPC
IPCIPC
IPC
 
Interprocess communication
Interprocess communicationInterprocess communication
Interprocess communication
 
virtual hosting and configuration
virtual hosting and configurationvirtual hosting and configuration
virtual hosting and configuration
 
Characteristics of cloud computing
Characteristics of cloud computingCharacteristics of cloud computing
Characteristics of cloud computing
 
Iptables the Linux Firewall
Iptables the Linux Firewall Iptables the Linux Firewall
Iptables the Linux Firewall
 
Implementation of page table
Implementation of page tableImplementation of page table
Implementation of page table
 
Session hijacking
Session hijackingSession hijacking
Session hijacking
 
Nfs
NfsNfs
Nfs
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
 
Distributed file systems dfs
Distributed file systems   dfsDistributed file systems   dfs
Distributed file systems dfs
 
Interprocess communication (IPC) IN O.S
Interprocess communication (IPC) IN O.SInterprocess communication (IPC) IN O.S
Interprocess communication (IPC) IN O.S
 
Virtual machine security
Virtual machine securityVirtual machine security
Virtual machine security
 
Message passing in Distributed Computing Systems
Message passing in Distributed Computing SystemsMessage passing in Distributed Computing Systems
Message passing in Distributed Computing Systems
 
An introduction to system-oriented evaluation in Information Retrieval
An introduction to system-oriented evaluation in Information RetrievalAn introduction to system-oriented evaluation in Information Retrieval
An introduction to system-oriented evaluation in Information Retrieval
 
CS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSCS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMS
 

Destacado

Chapter 7 slides
Chapter 7 slidesChapter 7 slides
Chapter 7 slideslara_ays
 
Chapter 2 system models
Chapter 2 system modelsChapter 2 system models
Chapter 2 system modelsAbDul ThaYyal
 
Chapter 3 slides
Chapter 3 slidesChapter 3 slides
Chapter 3 slideslara_ays
 
Stij5014 distributed systems
Stij5014 distributed systemsStij5014 distributed systems
Stij5014 distributed systemslara_ays
 
Chapter 3 a
Chapter 3 aChapter 3 a
Chapter 3 alara_ays
 
Chapter 2 slides
Chapter 2 slidesChapter 2 slides
Chapter 2 slideslara_ays
 
Distributed Systems
Distributed SystemsDistributed Systems
Distributed SystemsRupsee
 
Chapter 2 slides
Chapter 2 slidesChapter 2 slides
Chapter 2 slidessoe sumijan
 
Chapter 10.slides
Chapter 10.slidesChapter 10.slides
Chapter 10.slideslara_ays
 
Chapter 9 slides
Chapter 9 slidesChapter 9 slides
Chapter 9 slideslara_ays
 
Ds objects and models
Ds objects and modelsDs objects and models
Ds objects and modelsMayank Jain
 
Data communications
Data communicationsData communications
Data communicationsUMaine
 
Chapter 1 slides
Chapter 1 slidesChapter 1 slides
Chapter 1 slidessoe sumijan
 
Chapter 3 slides (Distributed Systems)
Chapter 3 slides (Distributed Systems)Chapter 3 slides (Distributed Systems)
Chapter 3 slides (Distributed Systems)soe sumijan
 
Chapter 4 computer networks
Chapter 4   computer networksChapter 4   computer networks
Chapter 4 computer networksPratik Gupta
 

Destacado (20)

Chapter 7 slides
Chapter 7 slidesChapter 7 slides
Chapter 7 slides
 
Chapter 2 system models
Chapter 2 system modelsChapter 2 system models
Chapter 2 system models
 
Chapter 3 slides
Chapter 3 slidesChapter 3 slides
Chapter 3 slides
 
Stij5014 distributed systems
Stij5014 distributed systemsStij5014 distributed systems
Stij5014 distributed systems
 
Chapter 3 a
Chapter 3 aChapter 3 a
Chapter 3 a
 
Chapter 2 slides
Chapter 2 slidesChapter 2 slides
Chapter 2 slides
 
Chapter 1 slides
Chapter 1 slidesChapter 1 slides
Chapter 1 slides
 
Distributed Systems
Distributed SystemsDistributed Systems
Distributed Systems
 
Chapter 2 slides
Chapter 2 slidesChapter 2 slides
Chapter 2 slides
 
Chapter 10.slides
Chapter 10.slidesChapter 10.slides
Chapter 10.slides
 
Chapter 1 slides
Chapter 1 slidesChapter 1 slides
Chapter 1 slides
 
Chapter 7 security
Chapter 7 securityChapter 7 security
Chapter 7 security
 
Ch12
Ch12Ch12
Ch12
 
Chapter 9 slides
Chapter 9 slidesChapter 9 slides
Chapter 9 slides
 
Ds objects and models
Ds objects and modelsDs objects and models
Ds objects and models
 
Data communications
Data communicationsData communications
Data communications
 
Chapter 1 slides
Chapter 1 slidesChapter 1 slides
Chapter 1 slides
 
Chapter 13
Chapter 13Chapter 13
Chapter 13
 
Chapter 3 slides (Distributed Systems)
Chapter 3 slides (Distributed Systems)Chapter 3 slides (Distributed Systems)
Chapter 3 slides (Distributed Systems)
 
Chapter 4 computer networks
Chapter 4   computer networksChapter 4   computer networks
Chapter 4 computer networks
 

Similar a Chapter 4 slides

Similar a Chapter 4 slides (20)

Ipc
IpcIpc
Ipc
 
Lab manual cn-2012-13
Lab manual cn-2012-13Lab manual cn-2012-13
Lab manual cn-2012-13
 
ikh331-06-distributed-programming
ikh331-06-distributed-programmingikh331-06-distributed-programming
ikh331-06-distributed-programming
 
分散式系統
分散式系統分散式系統
分散式系統
 
CS6601 DISTRIBUTED SYSTEMS
CS6601 DISTRIBUTED SYSTEMSCS6601 DISTRIBUTED SYSTEMS
CS6601 DISTRIBUTED SYSTEMS
 
CHAPTER - 3 - JAVA NETWORKING.pptx
CHAPTER - 3 - JAVA NETWORKING.pptxCHAPTER - 3 - JAVA NETWORKING.pptx
CHAPTER - 3 - JAVA NETWORKING.pptx
 
Lecture6
Lecture6Lecture6
Lecture6
 
Pemrograman Jaringan
Pemrograman JaringanPemrograman Jaringan
Pemrograman Jaringan
 
#2 (UDP)
#2 (UDP)#2 (UDP)
#2 (UDP)
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
 
nw-lab_dns-server.pdf
nw-lab_dns-server.pdfnw-lab_dns-server.pdf
nw-lab_dns-server.pdf
 
Advance Java-Network Programming
Advance Java-Network ProgrammingAdvance Java-Network Programming
Advance Java-Network Programming
 
Unit 8 Java
Unit 8 JavaUnit 8 Java
Unit 8 Java
 
EN-04 (1).pptx
EN-04 (1).pptxEN-04 (1).pptx
EN-04 (1).pptx
 
Socket Programming - nitish nagar
Socket Programming - nitish nagarSocket Programming - nitish nagar
Socket Programming - nitish nagar
 
Network
NetworkNetwork
Network
 
Socket Programming
Socket  ProgrammingSocket  Programming
Socket Programming
 
Sockets
SocketsSockets
Sockets
 
Java 1
Java 1Java 1
Java 1
 
Networking and Data Access with Eqela
Networking and Data Access with EqelaNetworking and Data Access with Eqela
Networking and Data Access with Eqela
 

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