Download presentation
Presentation is loading. Please wait.
Published byDerek Osborne Modified over 9 years ago
1
1 Distribuerede systemer – 12. februar 2001 Presentation based on slides by Coulouris et al, modified by Jens B Jorgensen
2
2 Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley 2001
3
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 3 Interprocess communication - basics zIntegrating communication into a programming language paradigm. zTCP and UDP provide application program interfaces to communication. zRMI - Remote method invocation – allows an object to invoke a method in an object in a remote process. zRPC – Remote procedure call – allows a client to call a procedure in a remote server.
4
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 4 Interprocess communication - middleware layers
5
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 5 Interprocess communication – how? zMessage passing between a pair of processes can be supported by two message communication operations: send and receive. zInvolves: yCommunication of data. ySynchronization of the two processes (possibly). zQueue associated with each message destination. zSenders cause messages to be added to remote queues. zReceivers remove messages from local queues. zIssues: Reliability and ordering.
6
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 6 Interprocess communication – communication patterns zSynchronous communication: The sending and receiving processes synchronize at every message, the send and receive operations are blocking. zAsynchronous communication: The send operation is non-blocking, the receive operation may be either blocking or non-blocking.
7
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 7 Interprocess communication – ports and sockets (1) zMessages are sent to (Internet address, local port) pairs. zLocal port: Message destination within a computer, specified as an integer. zSocket: Endpoint for communication between processes. zInterprocess communication: Transmission of a message between a socket in one process and a socket in another process. zSockets are bound to ports.
8
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 8 Interprocess communication – ports and sockets (2) message agreed port any port socket Internet address = 138.37.88.249Internet address = 138.37.94.248 other ports client server Any process may use multiple ports to receive messages. A process cannot share ports with other processes on the same computer. Each socket is associated with either UDP or TCP.
9
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 9 UDP – User Datagram Protocol zA datagram sent by UDP is transmitted from a sending process to a receiving process without acknowledgements or retries. zA process which will apply UDP must create a socket and bind it to a local port. zA receiving process needs to specify an array of bytes in which to receive a message.
10
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 10 UDP – properties zNon-blocking send operation. zBlocking receive operation. zTimeouts may be applied. zFailure model: yOmission failures. yOrdering. zExamples of use: yDNS.
11
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 11 UDP – Java API zDatagramPacket: yArray of bytes containing message. yLength of message. yInternet address. yPort number. yMethods: new, getData, getLength, getPort, getAddress. zDatagramSocket: yMethods: new, send, receive, …
12
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 12 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 try { DatagramSocket aSocket = new DatagramSocket(); byte [] m = args[0].getBytes(); InetAddress aHost = InetAddress.getByName(args[1]); int serverPort = 6789; DatagramPacket request = new DatagramPacket(m, args[0].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())); aSocket.close(); }catch (SocketException e){System.out.println("Socket: " + e.getMessage()); }catch (IOException e){System.out.println("IO: " + e.getMessage());} }
13
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 13 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[]){ try{ DatagramSocket 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());} }
14
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 14 TCP – Transmission Control Protocol zTCP provides the abstraction of a stream of bytes to which data may be written and from which data may be read. zTCP uses: yconnect operation. yaccept operations. zThe client role involves creating a stream socket bound to any port and then making a connect. zThe server role involves creating a listening socket bound to a server port. zUpon accept, a connection between client and server established using a new socket.
15
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 15 TCP - properties zTCP hides: yMessage sizes. yLost messages. yFlow control. yMessage duplication and ordering. yMessage destinations. zFailure model: yEnsures (almost always) integrity and reliability. yCannot survive all situations. zExamples of use: HTTP, FTP, Telnet, SMTP.
16
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 16 External data representation and marshalling - basics zMotivation: Information in programs represented as data structures, information in messages consists of sequences of bytes. zIssues: yCharacter sets - ASCII vs. Unicode. yByte order – big-endian vs. little-endian. zTwo metods for data exchange: yConvert values to agreed external format before transmission. yTransmit values in sender’s format.
17
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 17 External data representation and marshalling - definitions zExternal data representation: An agreed standard for the representation of data structures and primitive values. zMarshalling: The process of taking a collection of data items and assembling them into a form suitable for transmission in a message. zUnmarshalling: The process of disassembling data on arrival to produce an equivalent collection of data items at the destination.
18
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 18 External data representation and marshalling - approaches zCORBA’s common data representation (CDR). zJava’s object serialization. zMarshalling and unmarshalling activities intended to be carried out by a middleware layer without any involvement on the part of the application programmer.
19
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 19 CORBA CDR Constructed types: 15 primitive types: short, long, unsigned short, … char, boolean, … CDR can represent all of the data types that can be used as arguments and return values in remote invocations in CORBA.
20
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 20 CORBA CDR message The flattened form represents aPerson struct with value: {‘Smith’, ‘London’, 1934} 0–3 4–7 8–11 12–15 16–19 20-23 24–27 5 "Smit" "h___" 6 "Lond" "on__" 1934 index in sequence of bytes4 bytes notes on representation length of string ‘Smith’ length of string ‘London’ unsigned long Marshalling operations can be generated automatically from the spec of the types of data items to be transmitted; types Described by CORBA IDL (interface definition language).
21
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 21 Java object serialization zIn Java RMI, both objects and primitive data values may be passed as arguments and results of method invocation. zSerialization: Flattening an object or a connected set of objects into a serial form. zUnserialization: The reverse. zInfo about class of each object necessary. zReferences serialized as handles. zReflection makes it possible to do serialization and unserialization in a generic manner.
22
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 22 Request-reply protocol - basics zClient-server communication in terms of the send and receive operations in the Java API for UDP datagrams. zUses remote object references, identifiers for a remote object that is valid throughout a distributed system. zCommunication primitives: ydoOperation. ygetRequest. ysendReply.
23
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 23 Request-reply protocol - operations public byte[] doOperation (RemoteObjectRef o, int methodId, byte[] arguments) sends a request message to the remote object and returns the reply. The arguments specify the remote object, the method to be invoked and the arguments of that method. public byte[] getRequest (); acquires a client request via the server port. public void sendReply (byte[] reply, InetAddress clientHost, int clientPort); sends the reply message reply to the client at its Internet address and port.
24
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 24 Request-reply protocol - communication Request ServerClient doOperation (wait) (continuation) Reply message getRequest execute method message select object sendReply
25
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 25 Request-reply protocol - message structure messageType requestId objectReference methodId arguments int (0=Request, 1= Reply) int RemoteObjectRef int or Method array of bytes
26
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 26 Request-reply protocol - failure model zProblems: yOmission failures. yNo guarantee of delivery in order. zTimeouts. zDiscarding duplicate request messages. zLost reply messages. zHistory.
27
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 27 HTTP – HyperText Transfer Protocol zHTTP used by web browsers to make requests to web servers and to receive replies from them. zClient requests specify a URL that includes the DNS hostname of a web server, an optional port number and an identification of a resource. zHTTP specifies: yMessages. yMethods. yArguments. yResults. yRules for representing data in messages.
28
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 28 HTTP - methods zGET: Requests the resource whose URL is given as argument. zHEAD: Similar to GET, but no data returned. zPOST: Can deal with data supplied with the request. zPUT: Can be used to store data. zDELETE: Server deletes resource. zOPTIONS: Server supplied client with list of methods. zTRACE: Server sends the request back.
29
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 29 HTTP - request message and reply message GET//www.dcs.qmw.ac.uk/index.htmlHTTP/ 1.1 URL or pathnamemethodHTTP versionheadersmessage body HTTP/1.1200OK resource data HTTP versionstatus codereasonheadersmessage body Request: Reply:
30
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 30 Group communication - basics zMulticast operation: An operation that sends a single message from one process to each of the members of a group of processes. zUseful for: yFault tolerance based on replicated services. yFinding the discovery servers in spontaneous networking. yBetter performance through replicated data. yPropagation of event notification.
31
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 31 Group communication – IP multicast zIP multicast is built on top of IP. zIP multicast allows the sender to transmit a single IP packet to a set of computers that form a multicast group. zA multicast group is specified by a class D internet address. zAt the application level, IP multicast is available only via UDP. zFailure model: Unreliable.
32
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 32 IP multicast - Java API zMulticastSocket (subclass of DatagramSocket), adding capability to join and leave multicast groups.
33
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 33 IP multicast - multicast peer joins a group and sends and receives datagrams (1) 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") try { InetAddress group = InetAddress.getByName(args[1]); MulticastSocket 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
34
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 34 IP multicast - multicast peer joins a group and sends and receives datagrams (2 - 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());} }
35
Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 35 Summary zIntroduction to interprocess communication. zPorts and sockets. zUDP. zTCP. zExternal data representation, marshalling; CORBA CDR, Java object serialization. zRequest-reply protocol. zHTTP. zGroup communication.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.