Distributed Systems Concepts and Design Chapter 4
4.1. Introduction –p
This Chapter Will Cover Characteristics of interprocess communication UDP and TCP from Programmers point of view Objects and data structures translated Design of suitable protocols
4.2. The API for the Internet protocols –p Characteristics of interprocess communication Connect Send Receive Disconnect
4.2. The API for the Internet protocols –p Characteristics of interprocess communication Synchronous and Asynchronous blocking send blocking receive non-blocking receive synchronous asynchronous Message Destination IP address & port Location transparency Send directly to processes Multicase to a group of process Reliability Ordering
4.2. The API for the Internet protocols –p Characteristics of interprocess communication Sockets – Both UDP and TCP use the socket abstraction, with provides an endpoint for communication between processes.
4.2. The API for the Internet protocols –p UDP datagram communication Message size (up to 2 16 bytes) Blocking: non-blocking send, blocking receive Timeouts Receive from any Failure Model (Omission, Ordering) Use of UDP (DNS, Less overhead)
4.2. The API for the Internet protocols –p Java API for UDP datagram 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();} }
4.2. The API for the Internet protocols –p Java API for UDP datagram 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());} }
4.2. The API for the Internet protocols –p TCP stream communication Characteristics Message size: Is Unlimited Lost Messages Flow Control Message duplication and order Message destination Outstanding Issues Matching of data items Blocking Treads Failure model Use of TCP: http, ftp, telnet, smtp
4.3. External data representation –p Different ways to represent int, float char... byte ordering for integer standard external data representation send in sender's format and indicates what format, receivers translate if necessary External data representation Three Approaches to External Data Representation CORBA Java’s object serialization XML
4.3. External data representation –p CORBA CDR message Primitive types Construction types CORBA IDL complier generates marshalling and unmarshalling routines Structure with string, unsigned long
4.3. External data representation and marshalling –p Java object serialization serialization and de-serialization flattened to be transmitted or stored on the disk
4.3. External data representation and marshalling –p Extensible markup language (XML) User-defined tags Different Apps agree on different set of tags. e.g. SOAP for web serves, tags are published Tags are in plain text Illustration of the use of a namespace in the person structure
4.4. Client-Server communication –p. 155ff Client-server communication Synchronous (client waits for a reply) Asynchronous (client doesn't wait)
Request/Reply Protocol p.157
Request/Reply Protocol pp UDP – Failure Handling Timeout Discard of duplicates Lost replies – idempotent operations History R, RR, RRA protocols Request - Request/Reply – Request/Reply/Acknowledge Reply
Request/Reply Protocols pp TCP implementation of Request/Reply Protocols HTTP example – allows persistent connection HTTP methods – GET, HEAD, POST, PUT, DELETE, OPTIONS, TRACE HTTP Message contents Request: Method/URL/HTTP Version/Header/msg Reply: HTTP Version/status code/reason/header/msg
Group Communication –p. 164 Multicast Operation a single message sent from one process to all members of a group High fault tolerance Can locate servers Better performance thru replication Propagation of event notifications
Group Communication p. 165 IP Multicast Multicast Group Multicast Routers Multicast Address Allocation
Group Communications pp IP Multicast – Failure Models Same as UDP – no guarantee of delivery Effects: Replicated services – all or none msg receipt Discovery servers – repeat requests Replicated Data –broadcast of data, not methods Event Notifications – app determines qualities
Unix Inter-process Communication pp IPC in Unix Layered on TCP and UDP protocol Socket System call – binding to an address Message destinations = socket address Msg queues at sending socket Networking protocol transmits msg Msg queues at receiving socket Receiving process makes system call to receive msg.
Unix Inter-process Communication pp Datagram Communication (UDP) Sockets identified in each communication Socket call Bind call Send to call Receive from call
Unix Inter-process Communication pp Stream Communication (TCP) One server is ‘listening’ for requests Socket call for stream socket + bind + listen Accept call, create new socket Client process issues socket, connect Both use write/read Both close when communication is finished
Inter-process Communication Summary UDP vs. TCP Marshalling data – CORBA, Java, XML Request/Reply Protocols Multicast Messages