OCT Chapter 4 Coulouris Interprocess CommunicationMiddleware layersSockets and portsUDP client sends a message to the server and gets a replyUDP server repeatedly receives a request and sends it back to the clientTCP client makes connection to server, sends request and receives replyTCP server makes a connection for each client and then echoes the client’s requestcontinuedExternal Data Representation and MarshallingSlide 10Slide 11Slide 12CORBA Common Data Representation (CDR) for constructed typesCORBA CDR messageCORBAJavaSlide 17Indication of Java serialized formRepresentation of a remote object referenceFigure 4.11 Request-reply communicationFigure 4.12 Operations of the request-reply protocolFailure model of request reply protocolFailure model – handling duplicatesFigure 4.13 Request-reply message structureRPC exchange protocols identified by Spector[1982]HTTP request messageHTTP SOAP messageTraditional HTTP reply messageHTTP Web Services SOAP reply messageOCT --OCTChapter 4 CoulourisInterprocess CommunicationOCT --Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 Middleware layersApplications, servicesMiddlewarelayersrequest-reply protocolmarshalling and external data representationUDP and TCPThischapterRMI and RPCOCT --Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 Sockets and portsmessageagreed portany portsocketsocketInternet address = 138.37.88.249Internet address = 138.37.94.248other portsclientserverOCT --Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 UDP client sends a message to the server and gets a replyimport java.net.*;import java.io.*;public class UDPClient{ public static void main(String args[]){ // args give message contents and server hostnameDatagramSocket aSocket = null; try {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())); }catch (SocketException e){System.out.println("Socket: " + e.getMessage()); }catch (IOException e){System.out.println("IO: " + e.getMessage());}}finally {if(aSocket != null) aSocket.close();} } }OCT --Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 UDP server repeatedly receives a request and sends it back to the clientimport 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();} }}OCT --Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 TCP client makes connection to server, sends request and receives replyimport java.net.*;import java.io.*;public class TCPClient {public static void main (String args[]) {// arguments supply message and hostname of destinationSocket 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.3String 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());}} }}OCT --Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 TCP server makes a connection for each client and then echoes the client’s requestimport 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 slideOCT --Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 continuedclass 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 serverString 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*/}}}}OCT --Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 3 © Addison-Wesley Publishers 2000 External Data Representation and MarshallingMessages consist of sequences of bytesInteroperability ProblemsBig-endian, little-endian byte ordering Floating point
View Full Document